Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. class Conexion{
  2.     private String bdd="prueba";
  3.     private String usuario="root";
  4.     private String clave="clave";
  5.     public static Connection con;
  6.     private Statement stmt;
  7.     public Conexion()
  8.     {
  9.             try{
  10.                 DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
  11.                 con=DriverManager.getConnection("jdbc:mysql://localhost/"+bdd,usuario,clave);
  12.             }catch(Exception e)
  13.             {
  14.                 e.printStackTrace();
  15.             }
  16.     }
  17.     public void Insertar(String sql){
  18.         try{
  19.             stmt=con.createStatement();
  20.             stmt.executeUpdate(sql);
  21.             stmt.close();
  22.             con.close();
  23.         }catch(SQLException e){
  24.             e.printStackTrace();
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement