我已經用Java編寫的代碼具有填充點文件。我得到的錯誤,我不知道爲什麼。所有路徑都已設置。異常在MySQL
Class.forName("com.mysql.jdbc.Driver");
Connection connects = DriverManager.getConnection("jdbc:mysql://localhost:3306/userlogin", "root","12345");
Statement stm = connects.createStatement();
ResultSet rs=stm.executeQuery("SELECT * FROM authors_4 WHERE self_authors='"+getTxt+"'");
int l=0;
/*if(rsx.next())
{
div = Double.parseDouble(rsx.getString("divs"));
}*/
do
{
if(l==0)
{
diva = Integer.parseInt(rs.getString("tot_pub"));
//fout.write("a [label=" + "\"" + rsx.getString(2) + "\\n" + rsx.getString(4) + "\"" + "color=blue,fontsize=24,fontcolor=red,style=filled];\r\n");
fout.write("\"" + rs.getString("self_authors") + "\"" + "[fixedsize=true, width="+diva+",height="+diva+", label=" + "\"" + rs.getString("self_authors") + "\\n" + rs.getString("tot_pub") + "\"" + "color=blue,fontsize=24,fontcolor=red,style=filled];\r\n");
l++;
}
divb = Integer.parseInt(rs.getString("tot_pub")) ;
fout.write("\"" + rs.getString("co_auths") + "\"" + "[fixedsize=true, width="+divb+",height="+divb+",label=" + "\"" + rs.getString("co_auths") + "\\n" + rs.getString("tot_pub") + "\"];" +"\r\n");
//fout.write("a ->" + "\"" + rsx.getString(6) + "\"" + "[penwidth=" + rsx.getString(8) +", label =" + rsx.getString(8) +" ];" + "\r\n");
fout.write("\"" + rs.getString("self_authors") + "\" ->" + "\"" + rs.getString("co_auths") + "\"" + "[penwidth=" + rs.getString("1") +", label =" + 1 +" ];" + "\r\n");
//System.out.println(rsx.getString(1));
}while(rs.next());
fout.write("}");
fout.close();
}
我寫的代碼很長,不能解釋,所以我只發佈了我收到異常的部分。
的例外是:
java.sql.SQLException: Before start of result set
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:855)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5773)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5693)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5733)
你是否已經看http://stackoverflow.com/questions/2120255/java-resultset-exception-before-start-of-result-set?rq=1?由於您顯示的代碼很少,我不確定它是否適用於您的案例, – 2013-04-07 04:02:43
您還應該使用參數來阻止潛在的SQL注入攻擊。 – 2013-04-07 04:05:37
@PM 77-1代碼已被添加用於進一步說明 – Shahzaib 2013-04-07 04:11:27