gpt4 book ai didi

java - 语句 "int executeUpdate = prest.executeUpdate();"抛出 SQLException

转载 作者:太空宇宙 更新时间:2023-11-04 12:43:40 25 4
gpt4 key购买 nike

这个问题已经困扰两天了。尝试了我能想到的一切。非常感谢您在这个问题上给我的任何帮助。提前致谢。`

try     {  // try get tx records
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection (
"jdbc:mysql://localhost:3306/brent?user=root&password=adsimysql");
Statement stmt = con.createStatement(); System.out.println("aaactivity3");
ResultSet rs = stmt.executeQuery("Select * from " + tbtx);
System.out.println("aaactivity4");
while (rs.next()) { // get tx records
dbrec = rs.getInt("trec"); // get input fields from database
dbacct = rs.getInt("tacct");
dbtxtype = rs.getInt("ttype");
dbtxno = rs.getInt("ttxno");
dbamt = rs.getDouble("tamt");
dbmed = rs.getDouble("tmed");
dbsaltx = rs.getDouble("tsaltx");
dbtxdat = rs.getInt("ttxdat");
dbxmail = rs.getInt("txmail");
dbbilldat = rs.getInt("tbilldat");
System.out.println("ApplyTX " + dbacct); // print
// try { // try write ts
//Class.forName("com.mysql.jdbc.Driver");
/*Connection con = DriverManager.getConnection (
"jdbc:mysql://localhost:3306/brent?user=root&password=adsimysql");
Statement stmt = con.createStatement();*/
PreparedStatement prest;
String updttx = "INSERT INTO "+ tbts + " (sacct, stype, srec, stxno, samt, smed, sstax, stxdat, sxmail, sbilldat) VALUES (?,?,?,?,?,?,?,?,?,?)";
//String updttx;
// updttx = "INSERT INTO "+ tbts + " (sacct, stype, srec, stxno, samt, smed, sstax, stxdat, sxmail, sbilldat) VALUES (?,?,?,?,?,?,?,?,?,?)";
prest = con.prepareStatement(updttx);
System.out.println("aaactivity5 " + dbacct);
prest.setInt(1,dbacct);
prest.setInt(2,dbtxtype);
prest.setInt(3,dbrec);
prest.setInt(4,dbtxno);
prest.setDouble(5,dbamt);
prest.setDouble(6,dbmed);
prest.setDouble(7,dbsaltx);
prest.setInt(8,dbtxdat);
prest.setInt(9,dbxmail);
prest.setInt(10,dbbilldat);
System.out.println("aaactivity6 "+ dbtxtype);
int executeUpdate = prest.executeUpdate(); // this statement is throwing SQLException
System.out.println("aaactivity7");
} // end while get tx records
} // end try get tx records and build ts file ********************************
catch(ClassNotFoundException e) {
}
catch(SQLException insertException) { System.out.println("SQLexception"+dbacct+" "+dbtxtype+" "+dbrec+" "+dbtxno+" "+dbamt+" "+dbmed+" "+dbsaltx+" "+dbtxdat+" "+dbxmail+" "+dbbilldat);
//displaySQLErrors (insertException);
}
} // end no ts

最佳答案

在您的 catch block 中添加此行 e.printStackTrace()。执行您的代码并检查 excat 错误。还有tbts是什么?这是表名吗?如果这是变量,其中您有表名,那么它的 nit 定义在您代码中的任何位置

关于java - 语句 "int executeUpdate = prest.executeUpdate();"抛出 SQLException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36563572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com