2017-05-13 6 views
0

CiteRowSet을 SQLite 및 Xerial 드라이버 https://bitbucket.org/xerial/sqlite-jdbc과 함께 사용하려고합니다. 그런CachedRowSet 및 SQLite JDBC 드라이버

내가 실행 호출하면() 메소드 : 다른 한편으로 결과 집합에

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) 

와 웁니다

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

나는 예외 : SQLException을 얻고있다 "SQLite는 JDBC 드라이버가 구현되지"() excecute() 작품을 실행하십시오 :

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

위의 예외는 오라클 예제에서입니다, 나는 코딩을 줄이고 여기에 전체 예외가 있지만 제 의견으로는 새로운 정보가 없습니다 : '예외 "메인"java.sql.SQLException : SQLite JDBC 드라이버에 의해 구현되지 않았습니다 First.main (First.java:79)의 First.rowSet1 (First.java:33)에서 com.sun.rowset.CachedRowSetImpl.execute (알 수없는 소스)의 com.sun.rowset.internal.CachedRowSetReader.readData (알 수없는 소스))' –

+0

나는 실제로 SQLite JDBC 드라이버에 의해 구현되지 않았지만 실제로는'CachedRowSetReader'에서 실제 코드를보고있는 SQLite 드라이버에서 어떤 메소드가 호출되는지를 포함하는 예외적 인 원인을 기대했을 것입니다. 예외 원인을 설정하지 않고 초기 예외의 메시지 ... 내가 말한대로 : 제 생각에는 그것은 다소 버그가 있으며 거의 ​​유용하지 않습니다. –

답변

0

불행히도 SQLite를 사용할 때 해결 방법을 구현해야하는 소수의 JDBC 기능이 있습니다. 이것은 그들 중 하나입니다. 아마 가장 좋은 대체 솔루션은 그와 함께 목록 <에 전체 결과 집합을 넣어>와 작업하는 것입니다 :

// 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의 대답은 당신의 드라이버가 지원되어 있지 않은 경우 기능을 시뮬레이션에 대한 설명을 포함하고 있습니다.