[英]Deleting a row in a Oracle 11g database using NetBeans
我试图删除数据库中与JTextField
中的某行匹配的行。 但是引发了一个异常,下面的代码没有告诉我为什么。 我能做什么?
try{Class.forName("oracle.jdbc.OracleDriver");
PreparedStatement pstmnt;
try (
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","hr","123")) {
pstmnt = conn.prepareStatement("delete from TEMP where matricRoll=?");
pstmnt.setString(1, matricRoll.getText());
pstmnt.executeUpdate();
conn.close();
pstmnt.close();
GI.setVisible(true);
ED.setVisible(false);
addingToFrame();
settingBounds();
} catch (SQLException ex) {JOptionPane.showMessageDialog(null,"error");}
} catch (ClassNotFoundException ex) {
}
String deleteSQL = "DELETE DBUSER WHERE USER_ID = ?";
try {
dbConnection = getDBConnection();
preparedStatement = dbConnection.prepareStatement(deleteSQL);
preparedStatement.setInt(1, 1001);
// execute delete SQL stetement
preparedStatement.executeUpdate();
System.out.println("Record is deleted!");
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
if (preparedStatement != null) {
preparedStatement.close();
}
if (dbConnection != null) {
dbConnection.close();
}
}
感谢您的关注..我发现了错误..我正在从无效列中删除...这是解决方法...
try{
Class.forName("oracle.jdbc.OracleDriver");
Connection conn;
PreparedStatement pstmnt;
try (conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","hr","123"))
{
pstmnt = conn.prepareStatement("delete from TEMP where MATRICRN=?");
String roll=matricRoll.getText();
int rollm=Integer.valueOf(roll);
pstmnt.setInt(1, rollm);
pstmnt.executeUpdate();
JOptionPane.showMessageDialog(null,"Deleted");
conn.close();
pstmnt.close();
GI.setVisible(true);
ED.setVisible(false);
addingToFrame();
settingBounds();
}
catch (SQLException ex)
{JOptionPane.showMessageDialog(null,"error"+ex);}
}
catch (ClassNotFoundException exe) {
JOptionPane.showMessageDialog(null,exe); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.