我在 con=createConnection(); 处收到语法错误;在 netbeans ide 中,我想将记录插入 mysql 数据库。怎么能纠正这个?
private void btnlogActionPerformed(java.awt.event.ActionEvent evt) {
user=txtuser.getText();
char[] pass=jPasswordField1.getPassword();
String passString=new String(pass);
**![con =createConnection();][1]**
try{
String str="INSERT INTO login(username,Password) VALUES ('" + user + "','" + passString + "')";
java.sql.PreparedStatement statement=con.prepareStatement(str);
statement.setString(1,user);
statement.setString(2,passString);
statement.executeUpdate();
}
catch(Exception e){
JOptionPane.showMessageDialog(null,"Exception: "+ e.toString());
}
public static void main(String args[]) {
try {
Class.forName("com.mysql.jdbc.Driver");
String connectionUrl = "jdbc:mysql://localhost/Stock?"+
"user=root&password=";
Connection con = DriverManager.getConnection(connectionUrl);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null,"SQL Exception: "+ e.toString());
} catch (ClassNotFoundException cE) {
JOptionPane.showMessageDialog(null,"Class Not Found Exception: "+ cE.toString());
}