Advertisement
Guest User

Untitled

a guest
Feb 15th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1.         try
  2.         {
  3.           // create a mysql database connection
  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.        
  9.           // the mysql insert statement
  10.           String query = " insert into usuario (nombre, apellido, es_coordinador, remuneracion)"
  11.             + " values (?, ?, ?, ?, ?)";
  12.  
  13.           // create the mysql insert preparedstatement
  14.           PreparedStatement preparedStmt = conn.prepareStatement(query);
  15.           preparedStmt.setString (1, emp.getNombre());
  16.           preparedStmt.setString (2, emp.getApellido());
  17.           preparedStmt.setBoolean(4, emp.esAdmin());
  18.           preparedStmt.setInt    (5, emp.getRemuneracion());
  19.  
  20.           // execute the preparedstatement
  21.           preparedStmt.execute();
  22.          
  23.           conn.close();
  24.         }
  25.         catch (Exception e)
  26.         {
  27.           System.err.println("Excepcion!");
  28.           System.err.println(e.getMessage());
  29.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement