我编写了一个程序,用一个单词列表填充数据库。问题是,它每次我尝试运行代码时都会抛出“线程中的异常”主“java.sql.SQLException:near”。“:语法错误”。 我转向你寻求帮助。
这是代码
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Random;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
以下是来源:
public Account() {
super("Create Account");
initComponents();
conn=javaconnect.ConnecrDb();
RandomAcc();
RandomMICR();
RandomPIN();
}
public void RandomAcc(){
Random ra=new Random();
jTextField1.setText(""+ra.nextInt(10000+1));
}
public void RandomMICR(){
Random ra=new Random();
jTextField2.setText(""+ra.nextInt(1000+1));
}
public void RandomPIN(){
Random ra=new Random();
jTextField3.setText(""+ra.nextInt(1000+1));
}
public void Bal(){
String sql="insert into Balances(Name,Acc,MICR_No,Balance) values(?,?,?,?)";
try{
pst=conn.prepareStatement(sql);
pst.setString(1, jTextField5.getText());
pst.setString(2, jTextField1.getText());
pst.setString(3, jTextField2.getText());
pst.setString(4, jTextField10.getText());
pst.execute();
}catch(Exception e){`enter code here`
JOptionPane.showMessageDialog(null, e);
}
}
String sql="insert into Account(Acc,Name,DOB,Pin,Acc_Type,Nationality,Caste,MICR_No,Gender,Mob,Address,Sec.Q,Sec.A,Balance) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
try{
pst=conn.prepareStatement(sql);
pst.setString(1, jTextField1.getText());
pst.setString(2, jTextField5.getText());
pst.setString(3,((JTextField)jDateChooser1.getDateEditor().getUiComponent()).getText());
pst.setString(4, jTextField3.getText());
pst.setString(5, (String) jComboBox1.getSelectedItem());
pst.setString(6, (String) jComboBox2.getSelectedItem());
pst.setString(7, jTextField6.getText());
pst.setString(8, jTextField2.getText());
jRadioButton1.setActionCommand("Male");
jRadioButton2.setActionCommand("Female");
pst.setString(9, buttonGroup1.getSelection().getActionCommand());
pst.setString(10, jTextField7.getText());
pst.setString(11, jTextField4.getText());
pst.setString(12, (String) jComboBox3.getSelectedItem());
pst.setString(13, jTextField9.getText());
pst.setString(14, jTextField10.getText());
pst.execute();
JOptionPane.showMessageDialog(null, "Congrtz\n Account has been Created");
Bal();
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
由于
答案 0 :(得分:0)
String sql="insert into Account(Acc,Name,DOB,Pin,Acc_Type,Nationality,Caste,MICR_No,Gender,Mob,Address,Sec.Q,Sec.A,Balance) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
Sec.Q,Sec.A
列名称是?这是不允许的。