Hello, I am trying to extend an existing application to allow us to use SQLite. Currently, if we open an existing database, we rely on the Java metadata system to tell us what the column data types are of the pre-existing tables. Unfortunately, when using SQLiteJDBC (v042- nested), the JDBC metadata system always returns -1 for the column type. Please see example below, which I have modified from the introductory example given on the website. It now uses a TEXT field for the name, and an INTEGER field for salary. The JDBC metadata system has a number of constants that it should return to represent each type. Please see: http://java.sun.com/j2se/1.4.2/docs/api/java/sql/DatabaseMetaData.html#getTables(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String[]) http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Types.html http://java.sun.com/j2se/1.4.2/docs/api/constant-values.html#java.sql.Types.INTEGER
import java.sql.*; public class Test { public static void main(String[] args) throws Exception { Class.forName("org.sqlite.JDBC"); Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db"); Statement stat = conn.createStatement(); stat.executeUpdate("drop table if exists people;"); stat.executeUpdate("create table people (name TEXT, salary INTEGER);"); PreparedStatement prep = conn.prepareStatement( "insert into people values (?, ?);"); prep.setString(1, "Gandhi"); prep.setInt(2, 0); prep.addBatch(); prep.setString(1, "Turing"); prep.setInt(2, 1000000); prep.addBatch(); prep.setString(1, "Wittgenstein"); prep.setInt(2, 18890426); prep.addBatch(); conn.setAutoCommit(false); prep.executeBatch(); conn.setAutoCommit(true); ResultSet rs = stat.executeQuery("select * from people;"); while (rs.next()) { System.out.println("name = " + rs.getString("name")); System.out.println("salary = " + rs.getString("salary")); } System.out.println("--------------------------------------------"); DatabaseMetaData meta = conn.getMetaData(); rs = meta.getColumns("test.db", null, "people", null); while (rs.next()) { String columnName = rs.getString(4); int sqlType = rs.getInt(5); System.out.println("type of col " + columnName + " = " + sqlType); } rs.close(); conn.close(); } } When run, this outputs that the type of both columns are -1: name = Gandhi salary = 0 name = Turing salary = 1000000 name = Wittgenstein salary = 18890426 -------------------------------------------- type of col name = -1 type of col salary = -1 Any suggestions? This is fairly important to us, so I'd be more than willing to contribute to write code and tests to get this working. --Matthew --~--~---------~--~----~------------~-------~--~----~ Mailing List: http://groups.google.com/group/sqlitejdbc?hl=en To unsubscribe, send email to [EMAIL PROTECTED] -~----------~----~----~----~------~----~------~--~---