The statements used to query JDBC preparedstatement today are as follows:
Class. forname ("com. MySQL. JDBC. Driver"); <br/> string url = "JDBC: mysql: // localhost: 3306/translate? Characterencoding = utf8 "; <br/> string SQL =" select ID, title, search_title, content from article "; <br/> connection conn = drivermanager. getconnection (URL, "root", "123456"); <br/> preparedstatement PS = Conn. preparestatement (SQL); <br/> resultset rs = ps.exe cutequery (); <br/> Rs. close (); <br/> ps. close (); <br/> Conn. close ();
This error is always reported:
Exception in thread "Main" Java. Lang. outofmemoryerror: Java heap Space
At com. MySQL. JDBC. Buffer. getbytes (buffer. Java: 198)
At com. MySQL. JDBC. Buffer. readlenbytearray (buffer. Java: 318)
At com. MySQL. JDBC. mysqlio. extractnativeencodedcolumn (mysqlio. Java: 3567)
At com. MySQL. JDBC. mysqlio. unpackbinaryresultsetrow (mysqlio. Java: 3483)
At com. MySQL. JDBC. mysqlio. nextrow (mysqlio. Java: 1391)
At com. MySQL. JDBC. mysqlio. readsinglerowset (mysqlio. Java: 2369)
At com. MySQL. JDBC. mysqlio. getresultset (mysqlio. Java: 451)
At com. MySQL. JDBC. mysqlio. readresultsforqueryorupdate (mysqlio. Java: 2076)
At com. MySQL. JDBC. mysqlio. readallresults (mysqlio. Java: 1451)
At com. MySQL. JDBC. serverpreparedstatement. serverexecute (serverpreparedstatement. Java: 1314)
At com.mysql.jdbc.serverpreparedstatement.exe cuteinternal (serverpreparedstatement. Java: 740)
At com.mysql.jdbc.preparedstatement.exe cutequery (preparedstatement. Java: 1467)
However, according to the Doc found on the Internet, this problem will not occur by default, because the automatic optimization of Java return will not cause memory overflow. Think twice about it.
I did not intend to find an introduction later.
Add two attributes to the URL connection string: usecursorfetch = true & defaultfetchsize = 100.