Robert13
Robert13

Reputation: 21

Problems connecting to a database. Java/SQLite

try {
    con = DriverManager.getConnection("jdbc:sqlite:db/Freepark.sqlite");
} catch (SQLException e) {
    // TODO Auto-generated catch block
    System.out.println("error al buscar la base de datos");
}

I am trying to do my first queries on an SQL database but I am having problems connecting to it. I think the problem is the URL for sure. The project name is BaseTest and inside project folder I have a subfolder called db and inside it is Freepark.sqlite. When I run the project the println message appears so I know that the problem is the URL. Things like class.forName are already done above this code sample.

Upvotes: 0

Views: 126

Answers (2)

hvgotcodes
hvgotcodes

Reputation: 120168

You are losing all of the exception information in your catch block. let the exception bubble up or otherwise print it.

you need to do something like

Class.forName("org.sqlite.JDBC");  
connection = DriverManager.getConnection("jdbc:sqlite:pathtodb");

Upvotes: 2

Woot4Moo
Woot4Moo

Reputation: 24316

First and foremost don't swallow the exception, which is what you are doing and why you are unable to figure out the root cause.

Upvotes: 2

Related Questions