- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何解决代码中的此错误
java.sql.SQLException: Column count doesn't match value count at row 1
我已经创建了一个数据库雇员列表,其中包含 SQL 中的表信息带字段
| Type |
| NAME | varchar(100) |
| FATHER_NAME | varchar(100) |
| MOTHER_NAME | varchar(100) |
| LAST_NAME | varchar(100) |
| GENDER | varchar(1) |
| DOB | int(2) |
| MOB | varchar(10) |
| YOB | int(4) |
| ADDRESS | varchar(200) |
| PHONE | int(10) |
| EMAIL | varchar(100) |
| PAN | varchar(12) |
| ADDHAR | int(10) |
<小时/>
package employeemid;
import employeemid.DatabaseConnection;
import javax.swing.*;
import com.mysql.jdbc.PreparedStatement;
import java.awt.*;
import java.awt.event.*; // importing event package for event listener
import java.sql.Connection;
import java.sql.Statement;
public class RegForm{
//Creating Static variables
static JTextField name_txt ;
static JTextField fname_txt;
static JTextField mname_txt;
static JTextField lname_txt;
static JRadioButton male;
static JRadioButton female;
static JComboBox day;
static JComboBox month;
static JComboBox year;
static JTextArea add_txtArea;
static JTextField phone_txt;
static JTextField email_txt;
static JTextField pc_txt;
static JTextField a_txt;
static JCheckBox chkbox;
static JButton submit_btn;
static JTextArea output_txtArea;
//public static void main(String args[])
public RegForm()
{
/* ---------------------------------- Creating JFrame -------------------------------------------------------- */
// 1 : Creating a frame using JFrame class
JFrame frame=new JFrame("Registration Form Example");
frame.setVisible(true);
frame.setBounds(200,100,700,600 );
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 2 : setting background color of Frame.
Container c=frame.getContentPane();
c.setLayout(null);
c.setBackground(Color.cyan);
/*---------------------------------- Creating JLabel for Heading Text ------------------------------------------- */
Font f=new Font("Arial",Font.BOLD,20); // Creating font style and size for heading
// 3 : creating JLabel for Heading
JLabel heading_lbl=new JLabel();
heading_lbl.setBounds(250,5,200,40);
heading_lbl.setText("<html><font><u><b>Registration Form</b></u></html>");
// applying font on heading Label
heading_lbl.setFont(f);
/* ----------------------------------- Creating Global Font style for all components ------------------------------ */
Font f1=new Font("Arial",Font.BOLD,14);
/* ----------------------------------- Creating components for Registration details ---------------------------------- */
// 4 : Creating JLabel for Name
JLabel name_lbl=new JLabel("Name : ");
name_lbl.setBounds(50,80,100,30);
// Creating JTextField for Name
name_txt=new JTextField();
name_txt.setBounds(180,80,180,30);
// 5 : Creating JLabel for Father's Name
JLabel fname_lbl=new JLabel("Father's Name : ");
fname_lbl.setBounds(50,120,150,30);
// Creating JTextField for Father's name
fname_txt=new JTextField();
fname_txt.setBounds(180,120,180,30);
// 6 : Creating JLabel for Mother's Name
JLabel mname_lbl=new JLabel("Mother's Name : ");
mname_lbl.setBounds(50,160,150,30);
// Creating JTextField for Mother's name
mname_txt=new JTextField();
mname_txt.setBounds(180,160,180,30);
// 7 : Creating JLabel for Last Name
JLabel lname_lbl=new JLabel("Last Name : ");
lname_lbl.setBounds(50,200,150,30);
// Creating JTextField for Mother's name
lname_txt=new JTextField();
lname_txt.setBounds(180,200,180,30);
// 8 : Creating JLabel for Gender
JLabel gender_lbl=new JLabel("Gender : ");
gender_lbl.setBounds(50,240,150,30);
// Setting Cursor for components
Cursor cur=new Cursor(Cursor.HAND_CURSOR);
// Creating JRadioButton for the Male
male=new JRadioButton("Male");
male.setBounds(180,240,70,30);
male.setBackground(Color.cyan);
male.setCursor(cur);
// Creating JRadioButton for the Female
female=new JRadioButton("Female");
female.setBounds(280,240,80,30);
female.setBackground(Color.cyan);
female.setCursor(cur);
// Creating ButtonGroup for the JRadioButtons
ButtonGroup gender_grp=new ButtonGroup();
gender_grp.add(male); // adding male radio button in the ButtonGroup
gender_grp.add(female); // adding female radio button in the ButtonGroup
// 9 : Creating JLabel for Date of Birth
JLabel dob_lbl=new JLabel("Date of Birth : ");
dob_lbl.setBounds(50,280,100,30);
// Creating JComboBox for the day
String day_arr[]=new String[31];
for(int i=1;i<=31;i++)
day_arr[i-1]=Integer.toString(i);
day=new JComboBox(day_arr);
day.setBounds(180,280,40,30);
// Creating JComboBox for the month
String month_arr[]={"Jan","Feb","March","April","May","June","July","Aug","Sept","Oct","Nov","Dec" };
month=new JComboBox(month_arr);
month.setBounds(230,280,60,30);
// Creating JComboBox for the year
String year_arr[]=new String[70];
for(int i=1951;i<=2020;i++)
year_arr[i-1951]=Integer.toString(i);
year=new JComboBox(year_arr);
year.setBounds(300,280,60,30);
// 10 : Creating JLabel for the Address
JLabel add_lbl=new JLabel("Address : ");
add_lbl.setBounds(50,320,100,30);
// Creating JTextArea for the address
add_txtArea= new JTextArea();
add_txtArea.setBounds(180,320,180,100);
// 11 : Creating JLabel for the phone
JLabel phone_lbl=new JLabel("Phone No. : ");
phone_lbl.setBounds(50,450,100,30);
// Creating JTextField for the phone
phone_txt=new JTextField();
phone_txt.setBounds(180,450,180,30);
// 12 : Creating JLabel for the Email
JLabel email_lbl=new JLabel("Email : ");
email_lbl.setBounds(50,490,100,30);
// Creating JTextField for the Email
email_txt=new JTextField();
email_txt.setBounds(180,490,180,30);
// 13 : Creating JLabel for the Pan Card
JLabel pc_lbl=new JLabel("PanCard no: ");
pc_lbl.setBounds(50,530,100,30);
// Creating JTextField for the pan card
pc_txt=new JTextField();
pc_txt.setBounds(180,530,180,30);
// 14 : Creating JLabel for the Aadhaar
JLabel a_lbl=new JLabel("Aadhar no : ");
a_lbl.setBounds(50,570,100,30);
// Creating JTextField for the Aadhar
a_txt=new JTextField();
a_txt.setBounds(180,570,180,30);
// 15 : Creating JCheckBox for the license agreement
chkbox=new JCheckBox("I accept the terms and conditions");
chkbox.setBounds(50,610,300,30);
chkbox.setBackground(Color.cyan);
// 16 : Creating JButton for submit the details
submit_btn=new JButton("Submit");
submit_btn.setBounds(180,680,120,40);
submit_btn.setCursor(cur); // Applying hand cursor on the button
// 17 : Adding ActionListener on submit button
submit_btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
submit_action(event);
}
});
// 18 : Creating JTextArea for output
output_txtArea=new JTextArea();
output_txtArea.setBounds(380,80,500,320);
// 19 : Applying Global Font on all the JLabels
name_lbl.setFont(f1);
fname_lbl.setFont(f1);
mname_lbl.setFont(f1);
lname_lbl.setFont(f1);
gender_lbl.setFont(f1);
dob_lbl.setFont(f1);
add_lbl.setFont(f1);
phone_lbl.setFont(f1);
email_lbl.setFont(f1);
pc_lbl.setFont(f1);
a_lbl.setFont(f1);
// 20 : Applying Font on all JTextFields, JRadioButtons, JComboBox and JTextArea
name_txt.setFont(f1);
fname_txt.setFont(f1);
mname_txt.setFont(f1);
lname_txt.setFont(f1);
male.setFont(f1);
female.setFont(f1);
add_txtArea.setFont(f1);
phone_txt.setFont(f1);
email_txt.setFont(f1);
pc_txt.setFont(f1);
a_txt.setFont(f1);
chkbox.setFont(f1);
submit_btn.setFont(f1);
output_txtArea.setFont(f1);
// 21 : Adding label components to the container
c.add(heading_lbl);
c.add(name_lbl);
c.add(fname_lbl);
c.add(mname_lbl);
c.add(lname_lbl);
c.add(gender_lbl);
c.add(male);
c.add(female);
c.add(dob_lbl);
c.add(add_lbl);
c.add(phone_lbl);
c.add(email_lbl);
c.add(pc_lbl);
c.add(a_lbl);
// 22 : Adding JTextField, JTextArea, JComboBox, JCheckBox, JRadioButton to the container
c.add(name_txt);
c.add(name_txt);
c.add(fname_txt);
c.add(mname_txt);
c.add(lname_txt);
c.add(day);
c.add(month);
c.add(year);
c.add(add_txtArea);
c.add(phone_txt);
c.add(email_txt);
c.add(pc_txt);
c.add(a_txt);
c.add(chkbox);
c.add(submit_btn);
c.add(output_txtArea);
}
// 23 : Reading value from the Registration Form
public static void submit_action(java.awt.event.ActionEvent event){
if(chkbox.isSelected()==true)
{
String name=name_txt.getText();
String fname=fname_txt.getText();
String mname=mname_txt.getText();
String lname=lname_txt.getText();
String gender="Male";
if(female.isSelected()==true)
gender="Female";
String day_name=(String)day.getSelectedItem();
String month_name=(String)month.getSelectedItem();
String year_name=(String)year.getSelectedItem();
String add=add_txtArea.getText();
String phone=phone_txt.getText();
String email=email_txt.getText();
String pc=pc_txt.getText();
String a=a_txt.getText();
//PreparedStatement ps=conn.prepareStatement
//String query = "insert into data(Name,MiddleName,LastName,gender,Bday,Bmonth,Byear,Address,PhoneNo,Mail,PAN,Addhar) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
try {
Connection conn_1 = DatabaseConnection.getConnection();
//Statement stmt = conn_1.createStatement();
//first you "prepare" your statement (where the '?' acts as a kind of placeholder)
PreparedStatement st = (PreparedStatement) conn_1.prepareStatement( "insert into info (Name,MiddleName,LastName,gender,Bday,Bmonth,Byear,Address,PhoneNo,Mail,PAN,Addhar) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
//String query =
//now you bind the data to your parameters
st.setString(1, name_txt);
st.setString(2, fname_txt.getText());
st.setString(3, mname_txt.getText());
st.setString(4, lname_txt.getText());
st.setString(5, gender.toString());
st.setString(6, day.getSelectedItem().toString());
st.setString(7, month.getSelectedItem().toString());
st.setString(8, year.getSelectedItem().toString());
st.setString(9, add_txtArea.getText());
st.setString(10, phone_txt.getText());
st.setString(11, email_txt.getText());
st.setString(12, pc_txt.getText());
st.setString(13, a_txt.getText());
//and then you can execute it
st.executeUpdate();
} catch (Exception e) {
System.out.println(e);
}
// displaying value in the JTextArea
output_txtArea.setText(" Name : " +name + "\n Father's Name : " +fname +"\nMother's Name: "+mname+"\nLastName: "+lname+ "\n Gender : "+gender +
"\n Date of Birth : "+day_name + " "+month_name + " " +year_name +
"\n Address : "+add + " \n Phone no : "+phone +
"\n Email : "+email + "\nPan Card no: "+pc+ "\nAadhaar no"+a+ "\n ");
}
else
{
output_txtArea.setText("Please accept the terms and condition");
}
}
}
最佳答案
如果我正确地阅读了您的代码,则您的 SQL 插入语句中缺少名字列。所以你应该使用这个:
String sql = "INSERT INTO info (Name, FirstName, MiddleName, LastName, gender, ";
sql += "Bday, Bmonth, Byear, Address, PhoneNo, Mail, PAN, Addhar) ";
sql += "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
PreparedStatement st = (PreparedStatement) conn_1.prepareStatement(sql);
// then bind your values as you already are doing
关于java.sql.SQLException : Column count doesn't match value count at row 1 for prepared statements,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51952482/
我正在尝试将我的 xcode 应用程序存档到 Itunes,但我得到了 following errors : 1.) “配置文件不支持推送通知。” 2.) “配置文件不包含 aps-environme
我正在尝试为我们的组织构建一个 Web 应用程序,它将使用我们的 O365 进行身份验证。在尝试使用管理员帐户连接到域时,我遇到了这个错误,其中提到 admin..onmicrosoft.com(全局
当我尝试构建 MUAI 项目时,它给出错误“该项目不知道如何运行配置文件 sample.WinUI”。项目已构建但无法运行。我使用的是 Visual Studio 2022 Preview(17.0
当某项包含在列表中时,有一个查询要搜索,但当某项不在列表中时,则没有查询。 此查询查找在给定列表 cdiffnums 中没有 ContactNum 的 customer 对象。我该怎么做才能仅返回此列
我们有一个黑盒第三方 Java 程序,可以从某个位置获取输入文件并制作 PDF。每次输入时,它都会将 list 文件放在同一位置,这需要我们以受控方式提供文件。 list (或 .xen/.que)是
我看到这个has选择器,hasnt 选择器在哪里?我想查找不包含图像的表格。 最佳答案 类似$("table:not(:has(img))")? 关于jQuery: "Doesn' t 有“选择器?,
为什么?这让我发疯??? $(document).ready(function () { $('#slides1').bxSlider({ prev_
我是 kubernetes 的新手。 我无法使用 kubectl 进行部署,但我可以在 kubernetes 仪表板上看到所有部署。我该如何解决这个问题? user@master:~$ kubectl
这个问题已经有答案了: What do querySelectorAll and getElementsBy* methods return? (12 个回答) 已关闭 6 年前。 HTML JS
我有两个数组,一个包含字符串值,另一个包含整数值,尽管这可能很愚蠢,但我陷入了困境,我需要一点帮助,我想遍历两者,如果 arr1 包含 arr2 中不存在的项目,它将被推送到 newArray 这是我
我一直在尝试为我的网站安装一个 PHP 脚本,设置所有内容,通过脚本附带的 phpMyAdmin 导入 SQL 文件,但我面对的是一个空白页面,错误如下所示: File /home/user/publ
我正在努力将站点的服务器从 PHP 5.2.17 升级到 5.5,以使其在未来的升级中保持新鲜,并安装其他需要 PHP 5.4+ 的软件。 数据库有一个我正在测试的表,其中有许多列在初始 INSERT
我一直收到这个错误: Object doesn't support this property or method 每当我在 IE7 和 IE8 中运行我的代码时。这是它停止的代码: _renderU
我想使用正则表达式排除某些单词。 输入文本: aaa1234 cc bbb1234 c1234 cc dd aacc cccc ccadf cc 输出文本: aaa1234 bbb1234 c1234
我有一个名为 adjust_status 的存储函数和一个包含 status 列的表 users。 select adjust_status(status) as adjusted_status
我有一个表,其中有一列由插入前触发器填充,该列设置为 NOT NULL 并且没有DEFAULT VALUE。 当我执行 INSERT TABLE 而不传递此列时,我收到错误:1364 - Field
这个问题已经有答案了: Modify the value of each textfield based on original value using jQuery (3 个回答) 已关闭去年。 使
我正在阅读 this , 它说 @keyframes rules don't cascade, so animations never derive keyframes from more than
编辑:我解决了问题,请参阅答案中的链接。 我正在使用 XMLHttpRequest AJAX API 将来自不同网站的数据发送到我们在 PythonAnywhere 中的服务器。奇怪的事情发生了:根据
我已经阅读了 Linux 调用 dlopen() 和 dlsym() 的文档,它们分别打开一个动态库并在库中加载一个符号。 这些调用似乎等同于 Windows 的 LoadLibrary() 和 Ge
我是一名优秀的程序员,十分优秀!