I am trying to connect a Java program with a MariaDB through PhpMyAdmin on Eclipse Enterprise. I get this annoying error all the time, even though the database seems to be connected:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Order ( OrderId INT(64) NOT NULL AUTO_INCREMENT, address VARCHAR(20), dt DA...' at line 1
Here is my code:
package main;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class main {
public static void main(String[] args) throws ClassNotFoundException {
Connection conn = null;
Statement stmt = null;
try {
Class.forName("com.mysql.jdbc.Driver");
// db parameters
String url = "jdbc:mysql://ip_number:3307/test_db";
String user = "root";
String password = "root";
// create a connection to the database
conn = DriverManager.getConnection(url, user, password);
System.out.println("Connected!");
stmt = conn.createStatement();
String sqlCreate =
"CREATE TABLE IF NOT EXISTS Order (" +
" OrderId INT(64) NOT NULL AUTO_INCREMENT, " +
" address VARCHAR(20), " +
" dt DATE, " +
" status VARCHAR(20), " +
" PRIMARY KEY('OrderId'))";
stmt.execute(sqlCreate);
System.out.println("Created Order-table in given database...");
} catch(SQLException e) {
System.out.println(e.getMessage());
} finally {
try{
if(conn != null)
{
conn.close();
}
}catch(SQLException ex){
System.out.println(ex.getMessage());
}
}
}
}
I have watched everywhere on the web and on this site and corrected the syntax many times. I am also sure, that the syntax is correct, because, if I query direct the database on phpMyAdmin, the table is created. What I am doing wrong?