我試圖啓動一個hsqldb的嵌入式版本,並且它可以很好地與包含的工具一起工作,它們不會很慢或者其他任何東西。hsqldb極其緩慢的SELECT * FROM [table]
但是,當我嘗試使用下面的代碼獲取20行,它需要長達10秒的所有結果都印
Class.forName("org.hsqldb.jdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:hsqldb:hsql://127.0.0.1/woopwoop", "SA", "");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM ttris_users");
while(rs.next())
{
output += "<tr>";
output += "<td>" + rs.getString("id") + "</td>";
output += "<td>" + rs.getString("name") + "</td>";
output += "<td>" + rs.getString("password") + "</td>";
output += "<td>" + rs.getString("email") + "</td>";
//name, password, email
output += "</tr>";
}
我初始化一個非常簡單的方法服務器之前,這可能是爲什麼它運行緩慢,我如何優化它?
org.hsqldb.server.Server server = new org.hsqldb.server.Server();
server.setDatabaseName(1, "woopwoop");
server.setDatabasePath(1, "C:\\ttris\\db\\");
server.start();
在該被印刷在控制檯日誌,它顯示了查詢倍
[編輯] 繼承人日誌
[[email protected]]: [Thread[HSQLDB Server @1050e1f,5,main]]: handleConnection(Socket[addr=/127.0.0.1,port=37523,localport=9001]) entered
[[email protected]]: [Thread[HSQLDB Server @1050e1f,5,main]]: handleConnection() exited
[[email protected]]: [Thread[HSQLDB Connection @3e0ebb,5,HSQLDB Connections @1050e1f]]: 0:Trying to connect user 'SA' to DB (woopwoop)
[[email protected]]: [Thread[HSQLDB Connection @3e0ebb,5,HSQLDB Connections @1050e1f]]: 0:Connected user 'SA'
[[email protected]]: 0:SELECT * FROM ttris_users
[[email protected]]: [Thread[HSQLDB Server @1050e1f,5,main]]: handleConnection(Socket[addr=/127.0.0.1,port=37524,localport=9001]) entered
[[email protected]]: [Thread[HSQLDB Server @1050e1f,5,main]]: handleConnection() exited
[[email protected]]: [Thread[HSQLDB Connection @76fba0,5,HSQLDB Connections @1050e1f]]: 1:Trying to connect user 'SA' to DB (woopwoop)
[[email protected]]: [Thread[HSQLDB Connection @76fba0,5,HSQLDB Connections @1050e1f]]: 1:Connected user 'SA'
[[email protected]]: 1:SELECT * FROM ttris_users
[[email protected]]: [Thread[HSQLDB Server @1050e1f,5,main]]: handleConnection(Socket[addr=/127.0.0.1,port=37525,localport=9001]) entered
[[email protected]]: [Thread[HSQLDB Server @1050e1f,5,main]]: handleConnection() exited
[[email protected]]: [Thread[HSQLDB Connection @16dadf9,5,HSQLDB Connections @1050e1f]]: 2:Trying to connect user 'SA' to DB (woopwoop)
[[email protected]]: [Thread[HSQLDB Connection @16dadf9,5,HSQLDB Connections @1050e1f]]: 2:Connected user 'SA'
[[email protected]]: 2:SELECT * FROM ttris_users
的問題是在第一條目位於正在使用該數據的servlet中,現在已解決
這是爲什麼我很困惑自己的確切原因。這是一個非常簡單的例子,我試圖從官方文檔中學習。我已更正帖子以指示其一個表格和20行 – 2011-04-06 12:01:19
在執行前後放置日誌記錄,並在每個日誌中輸出當前時間,以便您可以看到延遲的位置。用這種方式跟蹤代碼,找出需要這麼久的代碼。 – 2011-04-06 12:04:52
根據您提供的信息,問題的最可能原因是您提供的代碼之外的某個循環。你如何初始化這段代碼?它坐在哪裏?它是在一個線程?你在哪裏開始線程?某處你做了27次導致這段代碼被執行的東西。順便問一下,它總是27次? – 2011-04-06 12:09:02