我用 Java 编写了一个代码,它必须填充一个点文件。我得到了错误,我不知道为什么。所有的路径都已经设置好了。
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)