2017-05-13 7 views
0

私はCiteRowSetをSQLiteとXerialドライバhttps://bitbucket.org/xerial/sqlite-jdbcで使用しようとしています。CachedRowSetとSQLite JDBCドライバ

私はそのようなexecute()メソッドを呼び出した場合:

Connection connection = DriverManager.getConnection("jdbc:sqlite:sample.db"); 
    CachedRowSet crs = new CachedRowSetImpl(); 
    crs.setCommand("select * from person"); 
    crs.execute(connection); 

を私は "SQLiteのJDBCドライバで実装されていません" のSQLException取得しています:一方のResultSetの上

at com.sun.rowset.internal.CachedRowSetReader.readData(Unknown Source) 
    at com.sun.rowset.CachedRowSetImpl.execute(Unknown Source) 
    at com.sun.rowset.CachedRowSetImpl.execute(Unknown Source) 
    at com.oracle.tutorial.jdbc.CachedRowSetSample.testPaging(CachedRowSetSample.java:100) 
    at com.oracle.tutorial.jdbc.CachedRowSetSample.main(CachedRowSetSample.java:273) 

をして移入excecute()のexeedcute insteedが正常に動作するok:

Connection connection = DriverManager.getConnection("jdbc:sqlite:sample.db"); 
    statement = connection.createStatement(); 
    ResultSet rs = statement.executeQuery("select * from person"); 
    CachedRowSet crs = new CachedRowSetImpl(); 
    crs.populate(rs); 

誰かがexecute()で何が問題なのか分かっていますか?

+0

完全な例外スタックトレースを送信してください。また、なぜあなたは 'CachedRowSet'を使用したいのですか?私の意見では、それはむしろバグであり、めったに役に立ちません。 –

+0

上記の例外はOracleの例であり、私はコーディングを減らしましたが、ここでは完全な例外ですが、私の意見では新しい情報はありません: 'スレッド内の例外" main "java.sql.SQLException:SQLite JDBCドライバで実装されていませんFirst.main(First.java:79)のFirst.rowSet1(First.java:33)のcom.sun.rowset.CachedRowSetImpl.execute(Unknown Source)のcom.sun.rowset.internal.CachedRowSetReader.readData(未知のソース) ) ' –

+0

実際にはSQLite JDBCドライバで実装されていないが、' CachedRowSetReader'の実際のコードを見て、それが新しい例外をスローするSQLiteドライバで呼び出されるメソッドを含む例外的な原因が予想されます例外の原因を設定せずに最初の例外のメッセージ...私が言ったように:私の意見ではむしろバギーであり、それはめったに有用ではありません。 –

答えて

0

残念ながら、SQLiteを使用する場合の回避策を実装する必要があるJDBC関数がいくつかあります。これはそれらの1つであることが起こります。おそらく最良の代替ソリューションを一覧<に結果セット全体を置く>とそれで動作するようにです:

// Variables. 
final int TIMEOUT_DEFAULT=30; 
String query = "select * from person"; 
ResultSet rs; 
Statement statement; 
List<String[]> people; 

... 

// Create query and execute. (Connection established, database open.) 
try {     
    statement = connection.createStatement(); 
    statement.setQueryTimeout(TIMEOUT_DEFAULT); 
    connection.setAutoCommit(true); 
    rs = statement.executeQuery(query); 
} catch (SQLException e) { 
    // If error, close connection & ignore close errors. 
    try { connection.close(); } 
     catch (SQLException e2) { /* Ignore */ } 
    // Throw new error. 
    throw new SQLException("Query failed",e); 
} 

// Retrieve results. 
try { 
    people = new ArrayList<>(); 
    while (rs.next()) { 
     people.add(new String[]{ 
      rs.getString(1), rs.getString(2), rs.getString(3) 
     }); 
    } 
} catch (SQLException e) { 
    // If error, close connection & ignore close errors. 
    try { connection.close(); } 
     catch (SQLException e2) { /* Ignore */ } 
    // Throw new error. 
    throw new SQLException("Error retrieving data",e); 
} 

// Close connection, ignore error. 
try { 
    connection.close(); 
} catch (SQLException e) { /* Ignore */ } 

// Print output. 
for (String[] p : people) { 
    System.out.println(Arrays.deepToString(p)); 
} 

答えthis postにそれはあなたのドライバでサポートされていない場合は機能をシミュレートに関するコメントが含まれています。