hsqldb extremely slow with SELECT * FROM [table]
Im trying to start an embedded version of hsqldb, and it works fine with the tool that are included, they're not slow or anything.
But when i try to use the following code to get 20 rows, it takes up to 10 seconds before all results are printed
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开发者_高级运维>";
}
I initialize the server in a very simple way, and that might be why it runs slow, how can i optimize it?
org.hsqldb.server.Server server = new org.hsqldb.server.Server();
server.setDatabaseName(1, "woopwoop");
server.setDatabasePath(1, "C:\\ttris\\db\\");
server.start();
In the log that is printed in the console, it shows the query 27 times
[Edit] heres the first entries in the log
[Server@1050e1f]: [Thread[HSQLDB Server @1050e1f,5,main]]: handleConnection(Socket[addr=/127.0.0.1,port=37523,localport=9001]) entered
[Server@1050e1f]: [Thread[HSQLDB Server @1050e1f,5,main]]: handleConnection() exited
[Server@1050e1f]: [Thread[HSQLDB Connection @3e0ebb,5,HSQLDB Connections @1050e1f]]: 0:Trying to connect user 'SA' to DB (woopwoop)
[Server@1050e1f]: [Thread[HSQLDB Connection @3e0ebb,5,HSQLDB Connections @1050e1f]]: 0:Connected user 'SA'
[Server@1050e1f]: 0:SELECT * FROM ttris_users
[Server@1050e1f]: [Thread[HSQLDB Server @1050e1f,5,main]]: handleConnection(Socket[addr=/127.0.0.1,port=37524,localport=9001]) entered
[Server@1050e1f]: [Thread[HSQLDB Server @1050e1f,5,main]]: handleConnection() exited
[Server@1050e1f]: [Thread[HSQLDB Connection @76fba0,5,HSQLDB Connections @1050e1f]]: 1:Trying to connect user 'SA' to DB (woopwoop)
[Server@1050e1f]: [Thread[HSQLDB Connection @76fba0,5,HSQLDB Connections @1050e1f]]: 1:Connected user 'SA'
[Server@1050e1f]: 1:SELECT * FROM ttris_users
[Server@1050e1f]: [Thread[HSQLDB Server @1050e1f,5,main]]: handleConnection(Socket[addr=/127.0.0.1,port=37525,localport=9001]) entered
[Server@1050e1f]: [Thread[HSQLDB Server @1050e1f,5,main]]: handleConnection() exited
[Server@1050e1f]: [Thread[HSQLDB Connection @16dadf9,5,HSQLDB Connections @1050e1f]]: 2:Trying to connect user 'SA' to DB (woopwoop)
[Server@1050e1f]: [Thread[HSQLDB Connection @16dadf9,5,HSQLDB Connections @1050e1f]]: 2:Connected user 'SA'
[Server@1050e1f]: 2:SELECT * FROM ttris_users
The issue was located in the servlet that was using the data, and is now resolved
Something is off here. I don't think you're giving us all the code we need to identify the problem.
If your log is showing the query executing 27 times, then this is the problem. Find out why. The code you pasted doesn't contain a loop that would cause this. So I have to assume that the code that's causing this was left out of the sample you gave us.
Put additional entries in the log and trace your program through execution. Find out where and why it is looping 27 times. The information you give us shows no indication of this.
Also, you say that you use this code to get 20 tables. Do you mean 20 records/rows? I only see a query from one table: ttris_users
.
That's very odd about showing the query 27 times; are you sure there's no way this code is being invoked more than once?
Regarding speeding this up: there is going to be a great deal of String copying, so much so that it will have a significant performance impact. Consider using a StringBuilder and append() calls:
output.append("<td>").append(rs.getString("id")).append("</td>");
精彩评论