我在java.sql.BatchUpdateException中遇到错误:ORA-00917:缺少逗号。

huangapple go评论82阅读模式
英文:

I' m getting error in java.sql.BatchUpdateException: ORA-00917: missing comma

问题

//  Statement stmt=con.createStatement();
String SQL = "insert into JMX(MAXThreads number(10),currentThreadCount number(10),MaxkeepAliveRequest number(10),threadPriority number(10), maxTime number(10),requestCount number(10),bytesReceived number(10),bytesSent number(10),processingTime number(10),modelerType varchar2(50) ,errorCount number(10)) values (?,?,?,?,?,?,?,?,?,?,?)";

try (PreparedStatement pst=con.prepareStatement(SQL)) {
    pst.setObject(1,  memoryMbean);
    pst.setObject(2,  osMbean);
    pst.setObject(3,  tmMbean);
    pst.setObject(4,  smMbean);
    pst.setObject(5,  grpMbean);
    pst.setObject(6,  grpMbean1);
    pst.setObject(7,  grpMbean2);
    pst.setObject(8,  grpMbean3);
    pst.setObject(9,  grpMbean4);
    pst.setObject(10,  grpMbean5);
    pst.setObject(11,  grpMbean6);
    
    pst.addBatch();

    pst.setObject(1,  memoryMbean);
    pst.setObject(2,  osMbean);
    pst.setObject(3,  tmMbean);
    pst.setObject(4,  smMbean);
    pst.setObject(5,  grpMbean);
    pst.setObject(6,  grpMbean1);
    pst.setObject(7,  grpMbean2);
    pst.setObject(8,  grpMbean3);
    pst.setObject(9,  grpMbean4);
    pst.setObject(10,  grpMbean5);
    pst.setObject(11,  grpMbean6);
    pst.executeBatch();
    con.commit();

    // JOptionPane.showMessageDialog(null,"Done");

} catch (SQLException e) {
    e.printStackTrace();
}

这是我得到的输出:

START
java.sql.BatchUpdateException: ORA-00917: missing comma

PROCESS COMPLETED
	at oracle.jdbc.driver.OraclePreparedStatement.executeLargeBatch(OraclePreparedStatement.java:9711)
	at oracle.jdbc.driver.T4CPreparedStatement.executeLargeBatch(T4CPreparedStatement.java:1447)
	at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:9487)
	at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:237)
	at com.jmx.Connection2.waitMethod(Connection2.java:304)
	at com.jmx.Connection2.main(Connection2.java:173)
英文:
						  	//  Statement stmt=con.createStatement();
 String SQL = "insert into JMX(MAXThreads number(10),currentThreadCount number(10),MaxkeepAliveRequest number(10),threadPriority number(10), maxTime number(10),requestCount number(10),bytesReceived number(10),bytesSent number(10),processingTime number(10),modelerType varchar2(50) ,errorCount number(10)) values (?,?,?,?,?,?,?,?,?,?,?)";
 
 
 
							    try (PreparedStatement pst=con.prepareStatement(SQL)) {
							        pst.setObject(1,  memoryMbean);
							        pst.setObject(2,  osMbean);
							        pst.setObject(3,  tmMbean);
							        pst.setObject(4,  smMbean);
							        pst.setObject(5,  grpMbean);
							        pst.setObject(6,  grpMbean1);
							        pst.setObject(7,  grpMbean2);
							        pst.setObject(8,  grpMbean3);
							        pst.setObject(9,  grpMbean4);
							        pst.setObject(10,  grpMbean5);
							        pst.setObject(11,  grpMbean6);
							        
							        pst.addBatch();

							        pst.setObject(1,  memoryMbean);
							        pst.setObject(2,  osMbean);
							        pst.setObject(3,  tmMbean);
							        pst.setObject(4,  smMbean);
							        pst.setObject(5,  grpMbean);
							        pst.setObject(6,  grpMbean1);
							        pst.setObject(7,  grpMbean2);
							        pst.setObject(8,  grpMbean3);
							        pst.setObject(9,  grpMbean4);
							        pst.setObject(10,  grpMbean5);
							        pst.setObject(11,  grpMbean6);
							        pst.executeBatch();
							        con.commit();

							       // JOptionPane.showMessageDialog(null,"Done");

							    } catch (SQLException e) {
							        e.printStackTrace();
							    }

This is my output im getting:
START
java.sql.BatchUpdateException: ORA-00917: missing comma

PROCESS COMPLETED
at oracle.jdbc.driver.OraclePreparedStatement.executeLargeBatch(OraclePreparedStatement.java:9711)
at oracle.jdbc.driver.T4CPreparedStatement.executeLargeBatch(T4CPreparedStatement.java:1447)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:9487)
at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:237)
at com.jmx.Connection2.waitMethod(Connection2.java:304)
at com.jmx.Connection2.main(Connection2.java:173)

答案1

得分: 1

你不需要指定类型,移除列类型:

"insert into JMX(MAXThreads, currentThreadCount, MaxkeepAliveRequest, 
threadPriority, maxTime, requestCount, bytesReceived, bytesSent, 
processingTime, modelerType, errorCount) values (?,?,?,?,?,?,?,?,?,?,?)";

另外,在调用addBatch之后为什么要再次设置值(重复设置)?

英文:

You don't need to specify the types, remove the columns types:

"insert into JMX(MAXThreads , currentThreadCount , MaxkeepAliveRequest 
, threadPriority , maxTime , requestCount , bytesReceived , bytesSent 
, processingTime , modelerType , errorCount ) values (?,?,?,?,?,?,?,?,?,?,?)";

Also why are you setting values again (duplicate) after addBatch?

huangapple
  • 本文由 发表于 2020年9月8日 18:16:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/63791786.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定