String s1 = Fname.getText();
String s2 = Lname.getText();
String s3 = usr.getText();
String s4 = psswd.getText();
String s5 = Eml.getText();
String s6 = sx.getText();
String s7 = DOB.getText();
String s8 = mob.getText();
String s9 = city.getText();
if((s3 != null) && (s4 != null))
try
{
String query = "INSERT INTO SIGNUP " + "(F_NAME varchar2(10), L_NAME varchar2(10), USER_ID varchar2(10), PASSWD varchar2(15), E_MAIL varchar2(30), SEX varchar2(7), DOB Date, MOB_NO varchar2(10), CITY varchar2(15))" + " VALUES(?,?,?,?,?,?,?,?,?)";
String user = "system";
String psswd = "sys123";
String url = "jdbc:oracle:thin:@localhost:1521:xe";
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection(url, user , psswd);
//System.out.println(query);
preparedStatement = connection.prepareStatement(query);
preparedStatement.setString(1, s1);
preparedStatement.setString(2, s2);
preparedStatement.setString(3, s3);
preparedStatement.setString(4, s4);
preparedStatement.setString(5, s5);
preparedStatement.setString(6, s6);
preparedStatement.setString(7, s7);
preparedStatement.setString(8, s8);
preparedStatement.setString(9, s9);
int temp = preparedStatement.executeUpdate();
if (temp > 0)
{
String msg = "Congratulations! Registration Successful...";
JOptionPane.showMessageDialog(b1, null, msg, temp);
}
}
catch (Exception e) {
// TODO: handle exception
System.out.println(e.getMessage());
e.printStackTrace();
}
嗯,我知道这是一个重复的问题并且已被多次询问过。但是,我仍然无法修复它。我检查过每个可能的错误,如空格,单引号,但它仍然无法正常工作。 UserID和Password字段不可为空。
答案 0 :(得分:4)
从INSERT中删除类型定义varchar2(10)
等。
"INSERT INTO SIGNUP " + "(F_NAME, L_NAME, USER_ID ...)"
答案 1 :(得分:2)
String query = "INSERT INTO SIGNUP " + "(F_NAME , L_NAME , USER_ID , PASSWD , E_MAIL, SEX , DOB Date, MOB_NO , CITY )" + " VALUES(?,?,?,?,?,?,?,?,?)";
我建议这是一种更好的方法。如果您使用的是Java,为什么不使用Entity JPA 2.2。它将管理您的CRUD操作。