Problems with Mariadb when creating table from java

1

Good morning,

I can not find the solution to my problem. From java, I create a table in phpmyadmin and insert data, which apparently does it well, I do not get any errors, however I find that if I want to enter data in a column that I created to put data manually, I find the following problem:

link

On the other hand, if I want to modify any of the added data from java, it will not let me:

link

As you can see, it refers to MariaDB, which if I'm not mistaken, should be the same as MySQL. In any case it's what I've found, I'm using phpmyadmin from XAMP. I do not even know where to throw, the code is apparently fine, maybe it's something about coding when creating the table, but just in case I also leave the code:

public class Conectate {
private String driver ="com.mysql.jdbc.Driver";
private String cadenaConexion ="jdbc:mysql://localhost/XboxOne";
private String pass = "";
private String usuario = "root";
public Connection con;

//public Conectate(Map<String,  Map<String, Item>> gamesByCountry, Map<String, String> codesByTitle,Map<String, String> countries) {
public Conectate(ArrayList<Item> games) {    

    try {
        Class.forName(driver);
        con = DriverManager.getConnection(cadenaConexion, usuario, pass);
        System.out.println("¡Conectado!");


        //CREAMOS LA TABLA
        Statement st = con.createStatement();

        st.executeUpdate("CREATE TABLE IF NOT EXISTS info_XboxOne (id INT AUTO_INCREMENT, PRIMARY KEY(id), "
                + "Juego_vinculado VARCHAR(500), Juego VARCHAR(500), Tipologia VARCHAR (500), Pertenece VARCHAR (500), "
                + "Nota VARCHAR (10), Descripcion_Ingles TEXT(4000), Descripcion_Castellano TEXT(4000), Pegi VARCHAR(10), Descripcion_Pegi VARCHAR(200),"
                + "Lanzamiento VARCHAR (50))");

        System.out.println( "Tabla creada!");


        for (Item game : games) {
            String titulo = game.getName();

            boolean isInsert;
            try (PreparedStatement ps = con.prepareStatement("SELECT * FROM info_XboxOne WHERE juego = ?")) {
                ps.setString(1, titulo);

                try (ResultSet rs = ps.executeQuery()) {
                    isInsert = !rs.next();
                }
            }

            if (isInsert) { //si se cumple esta condicción significa que el juego no está incluido, con lo que lo metemos
                try(PreparedStatement ps = con.prepareStatement("INSERT INTO info_XboxOne (Juego, Tipologia, Pertenece, "
                + "Nota, Descripcion_Ingles, Descripcion_Castellano, Pegi, Descripcion_Pegi"
                + ") VALUES (?,?,?,?,?,?,?,?)")) {

                    ps.setString(1,titulo);
                    ps.setString(2,game.getValues().get(Constants.TIPOLOGIA));
                    ps.setString(3,game.getValues().get(Constants.PERTENECE));                                            
                    ps.setString(4,game.getValues().get(Constants.NOTA));
                    ps.setString(5,game.getValues().get(Constants.DESCRIPCION_INGLES));
                    ps.setString(6,game.getValues().get(Constants.DESCRIPCION_CASTELLANO));
                    ps.setString(7,game.getValues().get(Constants.PEGI));
                    ps.setString(8,game.getValues().get(Constants.DESCRIPCION_PEGI));    

                    ps.executeUpdate();
                }
            } else {
                String query = "UPDATE info_XboxOne SET Tipologia = ?, Pertenece = ?, "
                + "Nota = ?, Descripcion_Ingles = ?, Descripcion_Castellano = ?, "
                + "Pegi = ?, Descripcion_Pegi = ? WHERE juego = ?";

                try (PreparedStatement ps = con.prepareStatement(query)) {
                    ps.setString(1,game.getValues().get(Constants.TIPOLOGIA));
                    ps.setString(2,game.getValues().get(Constants.PERTENECE));                                            
                    ps.setString(3,game.getValues().get(Constants.NOTA));
                    ps.setString(4,game.getValues().get(Constants.DESCRIPCION_INGLES));
                    ps.setString(5,game.getValues().get(Constants.DESCRIPCION_CASTELLANO));
                    ps.setString(6,game.getValues().get(Constants.PEGI));
                    ps.setString(7,game.getValues().get(Constants.DESCRIPCION_PEGI));
                    ps.setString(8,titulo);

                    ps.executeUpdate();
                }
            }           
    }

        /*
        for (Item game : games) {


            String titulo = game.getName();

            ResultSet rs = st.executeQuery("SELECT * FROM info_XboxOne WHERE juego = \"" + titulo + "\"");

            if (!rs.next()) { //si se cumple esta condicción significa que el juego no está incluido, con lo que lo metemos
                PreparedStatement ps = con.prepareStatement("INSERT INTO info_XboxOne (Juego, Tipologia, Pertenece, "
                + "Nota, Descripcion_Ingles, Descripcion_Castellano, Pegi, Descripcion_Pegi"
                + ") VALUES (?,?,?,?"
                + ",?,?,?,?"
                + ")");

                ps.setString(1,game.getName());
                ps.setString(2,game.getValues().get(Constants.TIPOLOGIA));
                ps.setString(3,game.getValues().get(Constants.PERTENECE));                                            
                ps.setString(4,game.getValues().get(Constants.NOTA));
                ps.setString(5,game.getValues().get(Constants.DESCRIPCION_INGLES));
                ps.setString(6,game.getValues().get(Constants.DESCRIPCION_CASTELLANO));
                ps.setString(7,game.getValues().get(Constants.PEGI));
                ps.setString(8,game.getValues().get(Constants.DESCRIPCION_PEGI));    

                ps.executeUpdate();

            } else {
                PreparedStatement ps = con.prepareStatement("UPDATE info_XboxOne SET Tipologia = ?, Pertenece = ?, Nota = ?, Descripcion_Ingles = ?, Descripcion_Castellano = ?, Pegi = ?, Descripcion_Pegi = ? WHERE juego = \"" + titulo + "\"");

                ps.setString(1,game.getValues().get(Constants.TIPOLOGIA));
                ps.setString(2,game.getValues().get(Constants.PERTENECE));                                            
                ps.setString(3,game.getValues().get(Constants.NOTA));
                ps.setString(4,game.getValues().get(Constants.DESCRIPCION_INGLES));
                ps.setString(5,game.getValues().get(Constants.DESCRIPCION_CASTELLANO));
                ps.setString(6,game.getValues().get(Constants.PEGI));
                ps.setString(7,game.getValues().get(Constants.DESCRIPCION_PEGI));

                ps.executeUpdate();
            }           
        }
       */

} catch (Exception e) {
            JOptionPane.showMessageDialog(null, "No se ha podido establecer la conexión con la DB" + e);
            e.printStackTrace();
        }

}

public String ConvertirObjectToString(Object Obj) {
String Str="";
if(Obj!=null){
    Str = Obj.toString();
}
return Str;
}


}

I hope someone can help me find the solution.

    
asked by JetLagFox 01.03.2017 в 21:31
source

0 answers