I'm creating a sign up page for a school program using Java. I have created a table with 3 users(Admin, Student Leader & Student) into the database by default. Now any students are able to sign up with their own username & Password. I tried to insert the text input by the users into the database table but the error is "org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (no such column: username)", i don't really get why is there missing database. This is my code:
JButton btnSubmit = new JButton("Submit");
btnSubmit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//declare variables
String username = "";
String password = "";
String name = "";
String AdminNo = "";
//get values using getText() method
username = txtUsername.getText().trim();
password = txtPassword.getText().trim();
name = txtName.getText().trim();
AdminNo = txtAdminNo.getText().trim();
if(username.equals("") || password.equals("")){
JOptionPane.showMessageDialog(null, "Name/Password is wrong");
}
else //Insert whether query is running properly
{
Connection conn = sqliteConnection.dbConnector();
String IQuery = "INSERT INTO Login(Username,Password,Name,AdminNo)" + "VALUES(username,password,name,AdminNo)";
System.out.println(IQuery); //Print to console
System.out.println("Connecting to a selected database");
try {
((Connection) conn).createStatement().execute(IQuery);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} // select the rows
}
}
});
And this is my Database Table: Login Table