我是jdbc的新手,我尝试通过数据库表单IDE连接。下面的代码是我写的;
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
DriverManager.registerDriver(new org.apache.derby.jdbc.ClientDriver());
Connection conn=DriverManager.getConnection("jdbc:derby://localhost:1527/sample","app","app");
preparedStatement ps=conn.prepareStatement("select name,zip,discount_code from customer where customer_id=?");
ps.setInt(1,Interger.parseInt(jTextField1.getText()));
ResultSet rs=ps.executeQuery();
if(rs.next()) {
jTextField2.setText(rs.getString(1));
jTextField3.setText(rs.getString(2));
jComboBox1.setSelectedItem(rs.getString(3));
}
} catch (NumberFormatException ex) {
ex.PrintStackTrace();
}catch (SQLException ex){
ex.printStackTrace();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new jdfrm().setVisible(true));
}
}
}
错误是......类“frm1.jdfrm”没有主要方法
答案 0 :(得分:1)
您的main
表单位于private void jButton1ActionPerformed
内..请检查括号
答案 1 :(得分:0)
你的括号看起来不对。在main方法之前需要另一个结束。