Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.cice.bbdd002;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- /**
- * Hello world!
- *
- */
- public class App
- {
- public static void main( String[] args )
- {
- try {
- //1.- Cargamos el driver en la base de datos
- Class.forName("com.mysql.jdbc.Driver");
- //2.- Creamos la conexión
- Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:8889/database","root", "root");
- //3.- Generación del Statement
- Statement statement = connection.createStatement();
- //4.- Strings de CRUDE
- String sqlCreate = "CREATE TABLE prueba (id INT NOT NULL AUTO_INCREMENT, nombre VARCHAR(30) NOT NULL, PRIMARY KEY (id))";
- statement.executeUpdate(sqlCreate);
- statement.close();
- connection.close();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment