2017-07-27 71 views
0

enter image description here我得到下面的異常java.lang.NumberFormatException:ForInputString 「7110332507339」 值java.sql.SQLException:丟失IN或OUT參數在指數:4

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

2)值java.sql.SQLException:缺少IN或OUT參數在指數:4

即使我給在輸入的時間正確的數據。我已經搜尋了很多來解決這個問題,但仍然得到例外。這裏是我的code.my與數據類型的數據庫列也附在圖片 任何人都可以建議我一個解決方案嗎?由於

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

可以請你的數據類型添加數據庫列在你的問題? – sForSujit

+0

編輯問題後添加在圖片中@sForSujit –

+0

謝謝,我會研究它 – sForSujit

回答

0

java.lang.NumberFormatException:ForInputString 「7110332507339」:這是因爲你的輸入值超出範圍。在使用Integer時,它應該高達2147483648.要解決這個問題,可以使用Long,BigInteger作爲數據類型。

值java.sql.SQLException:缺少IN或OUT參數在指數:4:這是因爲你將字符串轉換爲Date類型的列

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

第二個異常是由於外部catch.it指向的索引4是cnic和異常被拋出,因爲你告訴int的大小小於我的輸入值。不是由於日期。感謝您的幫助.. –

+0

@JAMSHAIDIQBAL感謝您的澄清 – sForSujit

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

謝謝..問題已解決。 –

相關問題