java.lang.NumberFormatException:ForInputString" 7110332507339" java.sql.SQLException:缺少Index :: 4处的IN或OUT参数

时间:2017-07-27 12:27:10

标签: java database oracle netbeans

enter image description here我收到以下例外

1)java.lang.NumberFormatException:ForInputString" 7110332507339"

2)java.sql.SQLException:缺少Index :: 4

的IN或OUT参数

即使我在输入时提供了正确的数据。我已经搜索了很多来解决这个问题,但仍然得到了例外。这是我的code.my数据类型的数据库列也附加在pic中 谁能建议我一个解决方案?感谢

 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);
}}

2 个答案:

答案 0 :(得分:0)

更改此

 try{ String emcnic=cnic.getText();
    int ecnic=Integer.parseInt(emcnic);
    pstmnt.setInt(4,ecnic);}catch(Exception q)
{JOptionPane.showMessageDialog(null,q);}

到这个

try{ String emcnic=cnic.getText();
    long ecnic=Long.parseLong(emcnic);
    pstmnt.setLong(4,ecnic);}catch(Exception q)
{JOptionPane.showMessageDialog(null,q);}

答案 1 :(得分:0)

java.lang.NumberFormatException:ForInputString“7110332507339”:这是因为您的输入值超出范围。当您使用Integer时,它应该最多为2147483648.要解决此问题,您可以使用Long,BigInteger作为数据类型。

java.sql.SQLException:缺少Index :: 4的IN或OUT参数:这是因为您要将字符串插入Date类型的列

 String edob=dob.getText();
    pstmnt.setString(5,edob);