1

所以我有这个代码..我运行它并给出了以下消息。

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);
     }
    }
}
4

0 回答 0