I have this class called programa
:
public class Programa {
public static void main(String[] args) throws SQLException{
Persona p = new Persona("a","b","a","13-04-1994");
String servidor = "jdbc:mysql://localhost/prueba";
Conexion con = new Conexion(servidor,"root","");
con.InsertarUsuario();
}
}
and this class called Conexion
:
package clases;
import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Conexion {
private static String user;
private static String psw;
private static String servidor;
private static String driver = "com.mysql.jdbc.Driver";
private static Connection con;
public Conexion(String servidor,String user,String psw){
this.user = user;
this.servidor = servidor;
this.psw = psw;
try{
Class.forName(driver);
con = (Connection) DriverManager.getConnection(servidor, user, psw);
System.out.println("Conexión correcta");
}
catch(Exception e){
System.out.println("COnexión fallida");
}
}
public void InsertarUsuario() throws SQLException{
String sql = "Insert into prueba values(null,'borja','sanchez'";
Statement st = con.createStatement();
st.executeQuery(sql);
con.close();
st.close();
}
}
because when I run the program I get the exception:
Can not issue data manipulation statements with executeQuery ().
How can I solve it? Thank you very much