Advertisement
Guest User

Untitled

a guest
Feb 15th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1.         try
  2.         {
  3.           // Crear la conexion
  4.           String myDriver = "org.gjt.mm.mysql.Driver";
  5.           String myUrl = "jdbc:mysql://localhost/test";
  6.           Class.forName(myDriver);
  7.           Connection conn = DriverManager.getConnection(myUrl, "root", "");
  8.           String query = " insert into usuario (nombre, apellido, es_coordinador, remuneracion)"
  9.             + " values (?, ?, ?, ?, ?)";
  10.           PreparedStatement preparedStmt = conn.prepareStatement(query);
  11.           preparedStmt.setString (1, emp.getNombre());
  12.           preparedStmt.setString (2, emp.getApellido());
  13.           preparedStmt.setBoolean(4, emp.esAdmin());
  14.           preparedStmt.setInt    (5, emp.getRemuneracion());
  15.           // execute the preparedstatement
  16.           preparedStmt.execute();
  17.           conn.close();
  18.         }
  19.         catch (Exception e)
  20.         {
  21.           System.err.println("Excepcion!");
  22.           System.err.println(e.getMessage());
  23.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement