Guest User

Untitled

a guest
Apr 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. package com.cice.bbdd002;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. /**
  9. * Hello world!
  10. *
  11. */
  12. public class App
  13. {
  14. public static void main( String[] args )
  15. {
  16. try {
  17.  
  18. //1.- Cargamos el driver en la base de datos
  19. Class.forName("com.mysql.jdbc.Driver");
  20.  
  21. //2.- Creamos la conexión
  22.  
  23. Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:8889/database","root", "root");
  24.  
  25. //3.- Generación del Statement
  26.  
  27. Statement statement = connection.createStatement();
  28.  
  29. //4.- Strings de CRUDE
  30.  
  31. String sqlCreate = "CREATE TABLE prueba (id INT NOT NULL AUTO_INCREMENT, nombre VARCHAR(30) NOT NULL, PRIMARY KEY (id))";
  32.  
  33. statement.executeUpdate(sqlCreate);
  34.  
  35. statement.close();
  36. connection.close();
  37.  
  38. } catch (ClassNotFoundException e) {
  39. e.printStackTrace();
  40. } catch (SQLException e) {
  41. e.printStackTrace();
  42. }
  43. }
  44. }
Add Comment
Please, Sign In to add comment