Java - Tabla Temporal Mysql - JAVA

 
Vista:

Tabla Temporal Mysql - JAVA

Publicado por Jose (1 intervención) el 29/02/2016 20:13:15
Cordial saludo Compañeros.
Tengo una BD en Mysql y ejecuto la la siguiente consulta:
1
2
3
4
5
6
7
8
CREATE TEMPORARY TABLE tmpMaximos ( id int , maximo int );
INSERT INTO tmpMaximos (id,maximo) SELECT id_actividad, max(parametros)
FROM practica group by id_actividad;
UPDATE actividad
    INNER JOIN tmpMaximos
       ON actividad.id_actividad = tmpMaximos.id
    SET actividad.Max_act= tmpMaximos.maximo;
SELECT * FROM tmpMaximos

Obtengo el resulta esperado, ahora lo que deseo es ejecutarla desde java pero me sale el siguiente error:
1
2
3
4
5
6
7
8
UA_resumen jButton1ActionPerformed
GRAVE: null
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'INSERT INTO tmpMaximos (id,maximo) SELECT id_actividad, max(parametros)
FROM pr' at line 2
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:422)


Lo que tengo en el evento del boton es esto:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
try {
        Statement st = conect.createStatement();
             //ResultSet rs = st.executeQuery(sql);
             st.executeUpdate("CREATE TEMPORARY TABLE tmpMaximos ( id int , maximo int );\n" +
                                "INSERT INTO tmpMaximos (id,maximo) SELECT id_actividad, max(parametros) \n" +
                                "FROM practica group by id_actividad;\n" +
                                        "\n" +
                                    "UPDATE actividad\n" +
                                    "    INNER JOIN tmpMaximos\n" +
                                    "       ON actividad.id_actividad = tmpMaximos.id\n" +
                                    "    SET actividad.Max_act= tmpMaximos.maximo");
          } catch (SQLException ex) {
        Logger.getLogger(UA_resumen.class.getName()).log(Level.SEVERE, null, ex);
}

Agradezco su ayuda y orientació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

Tabla Temporal Mysql - JAVA

Publicado por Tom (1831 intervenciones) el 29/02/2016 20:49:16
Solamente una cosa cada vez :)
Separa cada sentencia SQL en su propio executeTalyCual.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar