我收到以下异常
1)java.lang.NumberFormatException: ForInputString"7110332507339"
2)java.sql.SQLException: Index::4 处缺少 IN 或 OUT 参数
即使我在输入时给出了正确的数据。我已经进行了很多搜索来解决这个问题,但仍然遇到异常。这是我的代码。带有数据类型的数据库列也附在图片中有人能给我建议一个解决方案吗?谢谢
try{
Class.forName("oracle.jdbc.OracleDriver");
try (Connection conn =
DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:XE","hr","123"))
{
String qry1 = "insert into storeStaff
values(?,?,?,?,?,?,?,?,?)";
try {
pstmnt=conn.prepareStatement(qry1);
String EID=employeID.getText();
pstmnt.setString(1,EID);
String ename=name.getText();
pstmnt.setString(2,ename);
String efname=fatherName.getText();
pstmnt.setString(3,efname);
try{ String emcnic=cnic.getText();
int ecnic=Integer.parseInt(emcnic);
pstmnt.setInt(4,ecnic);}catch(Exception q)
{JOptionPane.showMessageDialog(null,q);}
String edob=dob.getText();
pstmnt.setString(5,edob);
String adress=address.getText();
pstmnt.setString(6,adress);
username.setText(EID);
pstmnt.setString(7,EID);
String pwd=password.getText();
pstmnt.setString(8,pwd);
String post=facultyChoice.getItem(facultyChoice.getSelectedIndex());
pstmnt.setString(9,post);
pstmnt.executeQuery();
if(EID!= null && ename!=null
&& efname!=null &&edob!=null && adress!=null && post!=null ){
JOptionPane.showMessageDialog(null, "Added");
}
} catch (SQLException eex)
{JOptionPane.showMessageDialog(null,"Error"+eex);}}
} catch (SQLException exx)
{JOptionPane.showMessageDialog(null,"Error"+exx);} catch
(ClassNotFoundException ex) {
JOptionPane.showMessageDialog(null,"Error"+ex);
}}
java.lang.NumberFormatException: ForInputString"7110332507339":这是因为您的输入值超出范围。由于您使用的是 Integer,因此它最大应为 2147483648。要解决此问题,您可以使用 Long、BigInteger 作为数据类型。
java.sql.SQLException:在 Index::4 处缺少 IN 或 OUT 参数:这是因为您正在将字符串插入日期类型的列
String edob=dob.getText();
pstmnt.setString(5,edob);
我是一名优秀的程序员,十分优秀!