I'm trying to run a program for employee entry checks I use the Derby driver in eclipse oxygen. Reading I came across some information and it was very similar to php and prepared statements, my problem is that when running my code the database was created, but I can not write it:
PreparedStatement tableCrt = connection.prepareStatement("CREATE
TABLE IF NOT EXISTS dbEmpleados(id SERIAL NOT NULL PRIMARY
KEY,nombre varchar(225) NOT NULL ,password varchar(225),fechareg
varchar(27))");
tableCrt.executeUpdate();
tableCrt.close();
I'm really lost in Java and I do not know how to continue, this is the script for my connection.
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class tableCreation {
private static final String DRIVER =
"org.apache.derby.jdbc.EmbeddedDriver";
private static final String JDBC_URL = "jdbc:derby:EvCo-
RegHuella;create=true";
Connection conn;
public tableCreation() {
try {
//tomamos la conexion y le pasamos la url
this.conn = DriverManager.getConnection(JDBC_URL);
//si this.conn NO es nulo....
if (this.conn != null) {
//SECCION EDITADA ------------------
PreparedStatement ps = this.conn.prepareStatement("TABLE IF NOT EXISTS dbEmpleados ID int NOT NULL AUTO_INCREMENT, Nombre varchar(255) NOT NULL,Apellidos varchar(255) NOT NULL, Puesto varchar(255) NOT NULL,FechaReg varchar(255) NOT NULL, PRIMARY KEY (ID),");
ps.executeUpdate();
ps.close();
}
//este es el catch del try nos va a tirar una SQLException en caso que falle la conexion
}catch(SQLException e) {
System.out.print("Fallo la conexion :( comprueba sintaxis o bien si el url esta correcto");
}
}
}
In the main activity just call:
tableCreation conectNcreate = new tableCreation() ;
As I said at the beginning, the database was created correctly (I see it even in my directory) what I do not see is that information is added to it, the table is not created nor can I add users or a password, in front of a lot of people thanks.