嗨,我一直在我的数据库java上收到此错误 [英] Hi I keep getting this error on my database java

查看:93
本文介绍了嗨,我一直在我的数据库java上收到此错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

   private void storeBttnActionPerformed(java.awt.event.ActionEvent evt) {                                          


        try
		{
                    System.out.println(passIdTextField.getText());
			 int  s1 =Integer.parseInt(passIdTextField.getText().trim());
			 String s2 = nameTextField.getText();
                         String s3 = malejCheckBox1.getText();
                         String s4 = femalejCheckBox2.getText();
                         int s5 = Integer.parseInt(phoneNumTextField.getText().trim());
                         String s6 = emailTextField.getText();
                         String s7   =address1TextField.getText();
                         String s8  = address2TextField.getText();
                         String s9 = cityTextField.getText();
                         String s10 =countyTextField.getText();
                         String s11 = fromComboBox.getSelectedItem().toString();
                         String s12 = toComboBox.getSelectedItem().toString();
                         String s13 =  departTextField.getText();
                         String s14=  arrivalTextField.getText();
                         int s15 = Integer.parseInt(adultTextField.getText().trim());
                         int s16 = Integer.parseInt(childrenTextField.getText().trim());
                         String s17 = classTextField.getText();
                         int s18 = Integer.parseInt(seatsTextField.getText().trim());
                         int s19 = Integer.parseInt(priceTextField.getText().trim());
                         int s20 = Integer.parseInt(lengthStayjTextField1.getText().trim());
                         int s21 = Integer.parseInt(cardNumTextField.getText().trim());
                         int s22 = Integer.parseInt(securityTextField.getText().trim());
                         int s23 = Integer.parseInt(ExpDatejTextField1.getText().trim());
                         
                         
                   
                        
             
                
                
                ///fix this here in order 
        
    System.out.println(s1+ s2 +s3 +s4 +s5 +s6 +s7 +s8 +s9 +s10 +s11 +s12 +s13 +s14 +s15  +s16 +s17+s18+s19+s20+s21+s22+s23);
    String newAir = "INSERT INTO Ticket(PassengerId, Name,Gender, Number, Email, Address1, Address2, City, County, From, To, DepartDate, ArrivalDate,Adult,Children,Class, Seats, Price, LengthStay,CardNumber,SecurityCode, ExpDate  )VALUES('"+s1+"', '"+s2+"','"+s3+"','"+s4+"', '"+s5+"','"+s6+"','"
        + ""+s7+"', '"+s8+"','"+s9+"','"+s10+"', '"+s11+"','"+s12+"','"
        + ""+s13+"', '"+s14+"','"+s15+"','"+s16+"', '"+s17+"','"+s18+"','"+s19+"','"+s20+"','"+s21+"','"+s22+"','"+s23+"')";

    stmt.executeUpdate(newAir);
    
    
System.out.println(newAir);

                        

			System.out.println(s1 + " stored in database");
                  
		}
		catch(SQLException e) {System.out.println("Error in creating new  row in database");
                count++;
                e.printStackTrace();}
                       
       

        // TODO add your handling code here:
    }                     





我尝试过:



i尝试将所有这些作为字符串和整数初始化,但它一直给我这个错误

ucanaccess.jdbc.UcanaccessSQLException :行列数不匹配

at net.ucanaccess.jdbc.UcanaccessStatement.executeUpdate(UcanaccessStatement.java:211)



当我按下存储按钮我不明白它运行但当我按下商店然后崩溃,我再次检查是否所有内容都在我的数据库中拼写正确



What I have tried:

i have tried intialising all these as a string and integers but it keeps giving me this error
ucanaccess.jdbc.UcanaccessSQLException: row column count mismatch
at net.ucanaccess.jdbc.UcanaccessStatement.executeUpdate(UcanaccessStatement.java:211)

when i press the store button i dont understand it runs but then crashes when i press store and i double checked to see if everything was correctly spelled in my database aswell

推荐答案

引用:

ucanaccess.jdbc.UcanaccessSQLException:行列数不匹配 essStatement.executeUpdate(UcanaccessStatement.java:211)

ucanaccess.jdbc.UcanaccessSQLException: row column count mismatch at net.ucanaccess.jdbc.UcanaccessStatement.executeUpdate(UcanaccessStatement.java:211)

消息非常清楚,值的数量与字段数不匹配。你的插入尝试在22个字段中记录23个值。



建议:永远不要通过连接字符串来构建SQL查询,打开一个名为SQL注入攻击的大门。

SQL注入 [ ^ ]

SQL注入 - 维基百科 [ ^ ]



[更新]

Message is pretty clear, the number of values do not match the number of fields. Your insert try to record 23 values in 22 fields.

Advise: Never build an SQL query by concatenating strings, in open doors to an attack named SQL injection.
SQL Injection[^]
SQL injection - Wikipedia[^]

[Update]

引用:

这是因为s3和s4,因为我有女性和男性作为性别

is this because of s3 and s4 as i have both female and male as gender

是的,你必须找到一个wat来组合 malejCheckBox1 femalejCheckBox2 成1个性别值。

Yes, you have to find a wat to combine malejCheckBox1 and femalejCheckBox2 into 1 gender value.


这篇关于嗨,我一直在我的数据库java上收到此错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆