java sql 结果

编程入门 行业动态 更新时间:2024-10-06 12:30:39

<a href=https://www.elefans.com/category/jswz/34/1770091.html style=java sql 结果"/>

java sql 结果

参见英文答案 > ResultSet exception – before start of result set                                    6个

我正在尝试在结果集循环中创建一个查询,但我不断收到错误“在结果集开始之前”.我尝试了很多不同的方法,但他们不断提出相同的错误.

有人可以帮帮我吗?

String insertSQL = "INSERT INTO MonthlyReportTable VALUES(NULL,"; //Primary Key.

String PlannetSchemeCode = "";

int ResponcibleAuthorityID = 0;

Statement stmt = ConnectionDetails.getNewConnectionPPARSDB().createStatement();

ResultSet resultsSet = stmt.executeQuery("SELECT * FROM planning_scheme");

Statement insideStatement = ConnectionDetails.getNewConnectionPPARSDB().createStatement();

//Loop though each planning scheme and create the data for each field.

while (resultsSet.next())

{

PlannetSchemeCode = "'" + resultsSet.getString("ps_code") + "'";

//Planning Scheme Primary Key

insertSQL += PlannetSchemeCode + ",";

/*

//Responsible Authority ID

insertSQL += "'" + String.valueOf(

ResponcibleAuthorityID = MySQLUtil.getResults(

ConnectionDetails.Database_Connection_PPARSDB,

"SELECT resp_authority_id " +

"FROM resp_authority_to_ps " +

"WHERE ps_code = " + PlannetSchemeCode

)

.getInt("resp_authority_id")

) + "'";

*/

ResultSet insideResultsSet =

insideStatement.executeQuery(

"SELECT resp_authority_id " +

"FROM resp_authority_to_ps " +

"WHERE ps_code = " + PlannetSchemeCode

);

//ERROR HERE, some reason results set is getting set wrong??

//Error here, this current results set is resetting the Results set.

ResponcibleAuthorityID = insideResultsSet.getInt("resp_authority_id");

//Total_Received_CM

//Add the rest of the values temporary.

int FeildsAdded = 3;

for(int i = 1 + FeildsAdded; i < 458; i++)

{

insertSQL += String.valueOf(0) + ",";

}

//Insert date and end SQL string.

insertSQL += "NOW()";

insertSQL += ")";

System.out.println(insertSQL);

//Do Insert in PPARS.

//stmt.executeQuery(insertSQL);

//Reset the SQL String for the new Row.

insertSQL = "INSERT INTO MonthlyReportTable VALUES(NULL,";

}

解决方法:

A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on.

您需要先调用ResultSet#next()才能读取返回的数据.

ResultSet insideResultsSet = insideStatement.executeQuery(

"SELECT resp_authority_id " +

"FROM resp_authority_to_ps " +

"WHERE ps_code = " + PlannetSchemeCode

);

if (insideResultsSet.next()) {

ResponcibleAuthorityID = insideResultsSet.getInt("resp_authority_id");

// etc...

}

标签:java,mysql,jdbc

来源: .html

更多推荐

java sql 结果

本文发布于:2024-03-14 05:38:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1735751.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:java   sql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!