所以我有这个代码..我运行它并发出以下信息。
run:
Java Result: -1073740940
BUILD SUCCESSFUL (total time: 21 seconds)
之后..即使以前的项目都运行正常甚至不会运行。他们都给了我相同的结果。我已经全神贯注地找到了解决方案,但论坛上的所有人都没有得到任何问题的问题。
这是代码..很久,我知道..但我希望它有所帮助。当我将SQL连接添加到注册按钮并编写saveName函数时,错误就开始了。
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.lang.Exception.*;
public class SmartStock extends JFrame implements ActionListener{
Connection conn = null;
Statement stmt = null;
public void saveName(String FirstName,String LastName,String SurName, String Password) throws SQLException{
String url = "jdbc:sqlserver//:localhost:1433/USERS";
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String userName = "";
String password = "";
try {
Class.forName(driver);
conn = DriverManager.getConnection(url, userName, password);
stmt = conn.createStatement();
stmt.executeUpdate("INSERT INTO USER_PERSONAL_DETAILS(forename, lastname, surname, password) VALUES ('','"+txtFName.getText()+ "','" +txtLName.getText()+"','"+txtSName.getText()+"','"+nwpassword.getText()+"'");
}catch (ClassNotFoundException ex) {
Logger.getLogger(SmartStock.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(SmartStock.class.getName()).log(Level.SEVERE, null, ex);
}
}
//In here is the JFrame for the code.. Long so I trimmed it off.
public void actionPerformed(ActionEvent e){
if(e.getSource()==btnSignup){
String fname = txtFName.getText();
String lname=txtLName.getText();
String sname=txtSName.getText();
String pword=nwpassword.getText();
try{
saveName(fname,lname,sname,pword);
} catch (SQLException ex) {
Logger.getLogger(SmartStock.class.getName()).log(Level.SEVERE, null, ex);
}
new SignUp();
dispose();
}
else if(e.getSource()==btnExit){
System.exit(0);
}
}
}