jeudi 5 novembre 2015

Connecting to SQLite from Java. Getting some disorder in commands

I have a factory class which "builds" different database connectors using one and the same interface. I have no trouble with MySQL and Postgre, but I do get some troubles when I try to connect and run some queries against SQLite database. So, this is the disorder I see:

SQL db = SQL_Factory.build("SQLite");
System.out.println("BEFORE CONNECT");
db.connect();
System.out.println("BEFORE SHOW");
List<String> tables = db.show_tables();

and inside connect() method I have these debugging commands:

try{
    cnx = DriverManager.getConnection("jdbc:sqlite:" + db_path);
    System.out.println("CONNECTED");
} 
....

As a result of running the code I expected to see this in the console:

BEFORE CONNECT
CONNECTED
BEFORE SHOW

However, what I see looks rather strange:

BEFORE CONNECT
BEFORE SHOW
CONNECTED

Indeed, I'm getting a lot of other errors, but it's quite obvious, that all of them result from this disorder - CONNECTED status appears long after other commands that need this connection to be set. So, I wonder where this async behaviour may come from and how to repair it? Thanks!

Aucun commentaire:

Enregistrer un commentaire