I clearly have a database named userinfo with a table named userName. I am using XAMPP
public class DatabaseHelper {
private static final String dbName = "userinfo";
Connection connection;
Statement stmt = null;
Timestamp date;
public Connection getConnection(){
String dbName = "userinfo";
String userName="root";
String password="12345678";
try {
Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
connection= DriverManager.getConnection("jdbc:mysql://localhost/"+dbName,userName,password);
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
createUsersTable();
return connection;
}
public void createUsersTable() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost/"+dbName);
stmt = connection.createStatement();
String sql = "CREATE TABLE IF NOT EXISTS Users"
+ "(Id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ " Firstname TEXT NOT NULL,"
+ " Lastname TEXT NOT NULL,"
+ " Username TEXT NOT NULL,"
+ " Password TEXT NOT NULL,"
+ " TotalAmount DOUBLE NOT NULL,"
+ " StockAmount DOUBLE NOT NULL,"
+ " Email TEXT NOT NULL" + ");";
stmt.executeUpdate(sql);
stmt.close();
connection.close();
} catch (Exception e) {
System.err.println(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
System.out.println("User table creation successful");
}
The error I am getting : WARNING: Loading FXML document with JavaFX API of version 8.0.171 by JavaFX runtime of version 8.0.131 java.sql.SQLSyntaxErrorException: Unknown database 'userinfo'
undate: this is the error i am getting now Mar 07, 2020 2:58:56 PM javafx.fxml.FXMLLoader$ValueElement processValue WARNING: Loading FXML document with JavaFX API of version 8.0.171 by JavaFX runtime of version 8.0.131 java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)