Advertisement
Guest User

Clase

a guest
Sep 4th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. public class Clientes
  2. {
  3.    
  4.     private static Scanner teclado = new Scanner(System.in);
  5.    
  6.     private static String db_host = "178.63.95.145";
  7.     private static String db_user = "root";
  8.     private static String db_pass = "2030xdc9h";
  9.     private static String db_name = "clientes";
  10.    
  11.     private static Connection conexion;
  12.     private static Statement st;
  13.    
  14.     public static void main(String[] args)
  15.     {
  16.         conectar();
  17.        
  18.         crearTablasDB();
  19.        
  20.     }
  21.    
  22.     private static void conectar()
  23.     {
  24.         try
  25.         {
  26.             Class.forName("com.mysql.jdbc.Driver");
  27.             conexion = DriverManager.getConnection("jdbc:mysql://"+db_host+"/"+db_name,db_user, db_pass);
  28.             st = conexion.createStatement();
  29.             System.out.print("Conexión establecida con éxito.");
  30.         }
  31.         catch (Exception ex)
  32.         {
  33.             System.out.println("No hemos podido conectar con MySQL: "+ ex.getMessage());
  34.         }
  35.     }
  36.    
  37.     private static void crearTablasDB()
  38.     {
  39.         try
  40.         {
  41.             st.execute("CREATE TABLE IF NOT EXISTS 'clientes' ( 'cliente' VARCHAR(20) NOT NULL, 'dni' VARCHAR(9) NOT NULL ) ENGINE='InnoDB';");
  42.         }
  43.         catch (SQLException e)
  44.         {
  45.             System.out.println("No se ha podido crear la tabla: "+e.getMessage());
  46.         }
  47.     }
  48.    
  49.     private static void guardarClientes()
  50.     {
  51.         String nombreCliente;
  52.         String dniCliente;
  53.        
  54.     }
  55.    
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement