Browse Source

Added connection

main
Jesus 2 years ago
parent
commit
9b6cfcb14a
1 changed files with 24 additions and 0 deletions
  1. +24
    -0
      src/com/jesuspinar/Main.java

+ 24
- 0
src/com/jesuspinar/Main.java View File

@ -1,7 +1,31 @@
package com.jesuspinar; package com.jesuspinar;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
//Editar USER y PWD
final String USER = "root";
final String PWD = "";
Connection con;
Statement query;
try {
// Cargamos driver
Class.forName("sun.jdbc.odbc.jdbcOdbcDriver");
// Establecemos conexion
con = DriverManager.getConnection("jdbc:odbc:pruebaodbc", USER, PWD);
query = con.createStatement();
String createQuery = "CREATE TABLE IF NOT EXISTS TEST (ID INTEGER() NOT NULL AUTOINCREMENT, NOMBRE VARCHAR(50) NOT NULL, APELLIDOS VARCHAR(50) NOT NULL) ";
String insertQuery = "INSERT INTO TEST VALUES('Juanjo','Pedraza'), ('Manel','Ruiz'), ('Yago','Cabrera')";
query.execute(createQuery);
query.execute(insertQuery);
} catch (Exception e) {
e.printStackTrace();
}
} }
} }

Loading…
Cancel
Save