Пробую подключиться к бд и создать запись в таблице.
Метод создания записи:
public void createField(String userId,
String userLogin,
String userPassword,
String userFirstName,
String userSecondName,
String userParentName,
String userPhoneNumber,
String userProfession,
String administrator) throws SQLException {
String[] insert = {"insert into users (user_id, user_login,user_password, "
+ "user_first_name, user_second_name, user_parent_name, "
+ "user_phone_number, user_profession, administrator) values "
+ "(" + userId + ", "
+ userLogin + ", "
+ userPassword + ", "
+ userFirstName + ", "
+ userSecondName + ", "
+ userParentName + ", "
+ userPhoneNumber + ", "
+ userProfession + ", "
+ administrator
+");"};
try {
statement = conn.createStatement();
for(String sql : insert){
statement.execute(sql);
}
}catch (SQLException e){
e.printStackTrace();
}
}
Вызов метода в мэйне:
DBRequest request = new DBRequest();
request.connection();
request.createField("1","1234567890","Qq4443123505", "Andrew", "Makarov", "Valerievich", "0939446910", "IT-specialst", "super");
DBRequest.closeConnection();
При запуске выдает:
Connect!
Connected!!
Disconnected
java.sql.SQLException: Unknown column 'Qq4443123505' in 'field list'
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2975)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1695)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3020)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2949)
at com.mysql.jdbc.Statement.execute(Statement.java:538)
at dataBase.DBRequest.createField(DBRequest.java:79)
at sample.Main.start(Main.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(LauncherImpl.java:821)
at com.sun.javafx.application.LauncherImpl$$Lambda$50/1232333336.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/940634419.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/1093519968.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/204709364.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda$38/139343823.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Методы подключения и отключения к бд:
public class DBRequest {
private static Connection conn = null;
private static Statement statement = null;
private final String DRIVER;
private final String USER_ROOT_NAME;
private final String PASSWORD_ROOT;
private final String URL;
public DBRequest(){
USER_ROOT_NAME = "root";
PASSWORD_ROOT= "Qq4443123505";
DRIVER = "com.mysql.jdbc.Driver";
URL = "jdbc:mysql://localhost/workcalendar";
}
public void connection() {
try{
Class.forName(DRIVER);
System.out.println("Connect!");
try {
conn = DriverManager.getConnection(URL, USER_ROOT_NAME, PASSWORD_ROOT);
System.out.println("Connected!!");
}catch (SQLException e){
e.printStackTrace();
}
}catch (ClassNotFoundException e){
e.printStackTrace();
}
}
public static void closeConnection(){
if (statement != null){
try {
statement.close();
}catch (SQLException e){
e.printStackTrace();
}
}
if(conn != null)
{
try {
conn.close();
}catch (SQLException e){
e.printStackTrace();
}
}
System.out.println("Disconnected");
}
}
Подскажите, что я делаю не так.