Guest User

Untitled

a guest
Dec 5th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. public void agregarcli(Cliente cli)
  2. {
  3.  
  4.     Statement st=null;
  5.     try
  6.    
  7.     {
  8.  
  9.         Class.forName("com.mysql.jdbc.Driver");
  10.          conexion = DriverManager.getConnection("jdbc:mysql://localhost/ivo9", "root", "llbntl");
  11.            st = conexion.createStatement();
  12.           st.executeUpdate("INSERT INTO clientes (nombre, direccion) VALUES ('"+cli.getNom()+"','"+cli.getDomic()+"' )");
  13.  
  14. }
  15.     catch(Exception e)
  16.    
  17.                 {
  18.                                    System.out.println(e.getMessage());
  19.    
  20.                 }
  21.     finally{
  22.         if(st!=null){
  23.         try {
  24.             st.close();
  25.     } catch (SQLException  e) {
  26.            
  27.             e.printStackTrace();
  28.     }      
  29.         }
  30.     if (conexion != null){
  31.             try {
  32.                     conexion.close();
  33.             } catch (SQLException  e) {
  34.                  
  35.                     e.printStackTrace();
  36.             }      
  37.     }
  38.     }  
  39.  }
Add Comment
Please, Sign In to add comment