Java - Problemas con Mariadb al crear tabla desde java

 
Vista:
Imágen de perfil de JetLagFox

Problemas con Mariadb al crear tabla desde java

Publicado por JetLagFox (1 intervención) el 02/03/2017 12:20:28
No consigo encontrar la solución a mi problema. Desde java, creo una tabla en phpmyadmin e inserto datos, que aparentemente lo hace bien, no me sale ningún error, sin embargo me encuentro que si quiero introducir datos en una columna que la he creado para meter datos de forma manual, me encuentro con el siguiente problema:

https://s16.postimg.org/msz6m38kl/Captura_de_pantalla_2017_02_28_a_las_22_37_40.png

Por otra parte, si quiero modificar alguno de los datos añadidos desde java tampoco me deja:

https://s12.postimg.org/6iana97v1/Captura_de_pantalla_2017_02_28_a_las_22_38_00.png

Como veis hace referencia a MariaDB, que si no me equivoco debería ser lo mismo que MySQL. En cualquier caso es con lo que me he encontrado, estoy usando phpmyadmin de XAMP. No sé ni para donde tirar, el código aparentemente está bien, quizá sea algo referente a la codificación a la hora de crear la tabla, pero por si acaso dejo también el código:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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;
}
 
 
}

Espero alguien pueda ayudarme a encontrar la solución.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder