I have a lineitem table with 6001215 rows of data and I wanted to get the result of this query SELECT * FROM LINEITEM
quickly, to then treat the data from the resultset in memory.
I have this code, but it's still very slow anyway.
String Query = "SELECT * FROM LINEITEM";
Properties p = new Properties();
p.setProperty("user", "root");
p.setProperty("password", "root");
p.setProperty("MaxPooledStatements", "10000");
p.setProperty("cachePrepStmts", "true");
p.setProperty("useServerPrepStmts", "true");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/tpch",p);
conn.setAutoCommit(false);
PreparedStatement preparedStatement = conn.prepareStatement(Query);
resultSet = preparedStatement.executeQuery(Query);
} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
Please try to make the database connection before the query run, making the connection in a method can reduce the performance when you will call that method again and again it will create db connection each time and use preparedStatement.executeQuery(); instead of preparedStatement.executeQuery(Query);
Use a POJO class implementation in order to save the Resulset fetched from the database table into a list of entities and then retrieve the column values whenever you want.