我是netbeans的新手并做我的功课 我正在尝试连接到derby数据库但公共静态void显示错误我不知道该怎么做这里是我的代码: import java.sql。; import javax.swing。;
public class addcriminal扩展了javax.swing.JFrame {
public addcriminal() {
initComponents();
}
@SuppressWarnings("unchecked")
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try{
String url="jdbc:derby://localhost:1527/criminal records ";
String username ="naim";
String password = "12345";
Connection con = DriverManager.getConnection(url,username,password);
Statement stmt = con.createStatement ();
String Query;
Query = "INSERT INTO CRIMINAL RECORDS (ID, NAME, AGE, ICNO, SEX, CRIME, PERIODS)VALUES ('"+txtno.getText()+"' , '"+txtname.getText()+"', '"+txtage.getText()+"', '"+txtic.getText()+"','"+txtic.getText()+"', '"+combosex.getSelectedItem()+"', '"+txtcrime.getText()+"', '"+txtperiods.getText()+"')";
stmt.execute(Query);
JOptionPane.showMessageDialog(null, "criminal recorded");
txtno.setText(null);
txtname.setText(null);
txtage.setText(null);
txtic.setText(null);
combosex.setSelectedItem(null);
txtcrime.setText(null);
txtperiods.setText(null);
}
catch(SQLException ex) {
JOptionPane.showMessageDialog(null, ex.toString());
}
public static void main(String args[]) { <<ERROR HERE
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new addcriminal().setVisible(true);
}
});
}
答案 0 :(得分:0)
在我看来你忘了你的catch语句中的结束花括号。
catch(SQLException ex) {
JOptionPane.showMessageDialog(null, ex.toString());
}