java.sql.SQLException: “.”附近:语法错误
java.sql.SQLException: near “.”: syntax error
我写了一个程序,用单词列表填充数据库。问题是,每次我尝试 运行 代码时,它都会抛出 "Exception in thread "main" java.sql.SQLException: near ".: syntax error"。
这个我求助于你。
这是代码
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);
}
}
谢谢
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
列名称吗?这是不允许的。
我写了一个程序,用单词列表填充数据库。问题是,每次我尝试 运行 代码时,它都会抛出 "Exception in thread "main" java.sql.SQLException: near ".: syntax error"。 这个我求助于你。
这是代码
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);
}
}
谢谢
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
列名称吗?这是不允许的。