2017-07-27 14 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:でも私は、入力時に正しいデータを与えているインデックス:: 4

でINまたはOUTパラメータがありません。私はこれを解決するために多くを検索しましたが、まだ例外を取得しています。ここで私の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にこの

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

: "7110332507339" ForInputString:あなたの入力値が範囲外であるためです。 Integerを使用する場合、最大2147483648にする必要があります。これを解決するには、Long、BigIntegerのいずれかをデータ型として使用できます。

ます。java.sql.SQLException:インデックス:: 4でINまたはOUTパラメータがありません:これはあなたがタイプ日

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

2番目の例外は外側のcatch.itが索引4にooutを指し示していて、それがcnicであり、intのサイズが入力値より小さいと言ったときに例外がスローされていたためです。日付によるものではありません。助けてくれてありがとう.. –

+0

@JAMSHAIDIQBAL清算をありがとう – sForSujit

0

変更この

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

ありがとうございます。問題は解決しました。 –

関連する問題