Print the table name in and after your while (tables.next()) loop.
Maybe an exception is being thrown.
Step through your code with a debugger or add a bunch of debug
print statements.
--- Em <[EMAIL PROTECTED]> wrote:
> I have several database files in a folder, each database contains
> only one table. I have this code to get database files from the
> folder, open the database, get data from one of the table and then
> proceed to the next database file. the problem is it only reads the
> first database file. in the next file, it can no longer see the
> table. can anybody help?
>
> here is the code:
>
> File directory = new File("D:/JavaSqliteTest/testDir");
> File[] files = directory.listFiles();
> for ( int i = 0; i < files.length; i++ ) {
> File file = files[i];
> String fileName = file.getName();
> try{
> Class.forName("org.sqlite.JDBC");
> Connection conn =
> DriverManager.getConnection("jdbc:sqlite:"+fileName);
> // get table name from the database so that the table name
> // in the query is changed every time a new database file is
> opened
> String tableName="";
> DatabaseMetaData meta = conn.getMetaData();
> ResultSet tables =
> conn.getMetaData().getTables(null,null,null,new String[]{"TABLE"});
>
> while (tables.next()) {
> tableName = tables.getString(3);
> }
>
> //create a query whose table name reflects the table in the
> current database
> String queryString = "SELECT TIMESTAMP, LOCATION_ID, MSG_TYPE,
> MSG_MESSAGE FROM " + tableName;
>
> Statement stmt = conn.createStatement();
> ResultSet rs = stmt.executeQuery(queryString);
>
> while (rs.next()) {
> int timestamp = rs.getInt("TIMESTAMP");
> String id = rs.getString("Location_id"); // Column
> 1
> String code = rs.getString("Msg_Type"); // Column 2
> String name = rs.getString("msg_Message"); // Column 3
>
> System.out.println("TimeStamp: "+ timestamp +" ID: "+id
> +" Msg_Type: "+code+" Message: "+name);
> }
> // Close the connection
> tables.close();
> stmt.close();
> rs.close();
> conn.close();
>
> }
> }
____________________________________________________________________________________
Choose the right car based on your needs. Check out Yahoo! Autos new Car
Finder tool.
http://autos.yahoo.com/carfinder/
--~--~---------~--~----~------------~-------~--~----~
Mailing List: http://groups.google.com/group/sqlitejdbc?hl=en
To unsubscribe, send email to [EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---