I'm trying to insert data into Database. I created Const class:
public class Const {
public static final String USER_TABLE = "users";
public static final String USER_ID = "idusers";
public static final String USER_FIRSTNAME = "firstname";
public static final String USER_LASTTNAME = "lastname";
public static final String USER_USERNAME = "username";
public static final String USER_PASSWORD = "password";
}
I checked and names on list are identical as Column names so there is no mistake. Also I rechecked configurations in this class and everything seems right:
public class Configs {
protected String dbHost = "localhost";
protected String dbPort = "3306";
protected String dbUser = "root";
protected String dbPass = "*******";
protected String dbName = "prog";
}
And here is DatabaseHandler class:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class Databasehandler extends Configs {
Connection dbConnection;
public Connection getDbConnection() throws ClassNotFoundException, SQLException {
String connectionString = "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName;
Class.forName("com.mysql.cj.jdbc.Driver");
dbConnection = DriverManager.getConnection(connectionString, dbUser, dbPass);
return dbConnection;
}
public void signUpUser(String firstName, String lastName, String userName, String password) {
String insert = "INSERT INTO" + Const.USER_TABLE + "(" + Const.USER_FIRSTNAME + "," + Const.USER_LASTTNAME + "," + Const.USER_USERNAME + "," + Const.USER_PASSWORD + ")" + "VALUES(?,?,?,?)";
try {
PreparedStatement prSt = getDbConnection().prepareStatement(insert);
prSt.setString(1, firstName);
prSt.setString(2, lastName);
prSt.setString(3, userName);
prSt.setString(4, password);
prSt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
While it's running I'm getting this error and not receiving results in a result grid:
Mon Sep 24 21:19:42 GET 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
java.sql.SQLSyntaxErrorException: Table 'prog.intousers' doesn't exist
String insert = "INSERT INTO" + Const.USER_TABLE + "(" + Const.USE...You are missing a space before and afterConst.USER_TABLE. Especially before.