Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.Statement;
- /**
- * Crear mesa
- * @author Administrator
- *
- */
- public class CreateTable {
- public static void main(String[] args) throws Exception {
- // Conéctate a la base de datos
- Connection c = null;
- // Enviar sentencias SQL a la base de datos
- Statement stmt = null;
- try {
- // Cargar controlador de datos, base de datos
- Class.forName("org.postgresql.Driver");
- // Dirección, nombre de usuario, contraseña
- c = DriverManager.getConnection(
- "jdbc:postgresql://127.0.0.1:5432/postgres", "postgres", "maxhito");
- System.out.println("Opened database successfully");
- //Statement stmt = conn.createStatement();
- // Enviar sentencias SQL a la base de datos
- stmt = c.createStatement();
- // Entrada de sentencia sql
- String sql = "CREATE TABLE BBQ " +
- "(ID INT PRIMARY KEY NOT NULL," +
- " NAME TEXT NOT NULL, " +
- " AGE INT NOT NULL, " +
- " ADDRESS CHAR(50), " +
- " SALARY REAL)";
- stmt.executeUpdate(sql);
- stmt.close();
- c.close();
- } catch ( Exception e ) {
- System.err.println( e.getClass().getName()+": "+ e.getMessage() );
- System.exit(0);
- }
- System.out.println("Table created successfully");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement