Example usage for java.sql DriverManager getConnection

List of usage examples for java.sql DriverManager getConnection

Introduction

In this page you can find the example usage for java.sql DriverManager getConnection.

Prototype

private static Connection getConnection(String url, java.util.Properties info, Class<?> caller)
            throws SQLException 

Source Link

Usage

From source file:Test.java

public static void main(String[] args) throws Exception {
    Connection conn = DriverManager.getConnection("...", "username", "password");
    Driver driver = DriverManager.getDriver("jdbc:derby://localhost:1527");
    System.out.println("Parent Logger" + driver.getParentLogger());

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Connection connection = DriverManager.getConnection(url, username, password);
    Statement stmt = connection.createStatement();

    // Load the data
    String filename = "c:/infile.txt";
    String tablename = "mysql_2_table";
    stmt.executeUpdate("LOAD DATA INFILE \"" + filename + "\" INTO TABLE " + tablename);

    // file is terminated by \r\n, use this statement
    stmt.executeUpdate(/*from w  w w  .  j  a  v a 2 s .  c o  m*/
            "LOAD DATA INFILE \"" + filename + "\" INTO TABLE " + tablename + " LINES TERMINATED BY '\\r\\n'");

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Class.forName("org.postgresql.Driver");
    Connection connection = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/testdb", "userName",
            "password");
    if (connection != null) {
        System.out.println("Connected");
    } else {/*from   w w w  .ja va2 s  . com*/
        System.out.println("Failed to make connection!");
    }
}

From source file:Test.java

public static void main(String[] args) throws Exception {
    Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/contact", "userName", "password");
    DatabaseMetaData metaData = con.getMetaData();
    ResultSet resultSet = metaData.getPseudoColumns("", "schemaName", "tableName", "");

    while (resultSet.next()) {
        System.out.println(resultSet.getString("TABLE_SCHEM ") + " - " + resultSet.getString("COLUMN_NAME "));
    }//w  w w. java  2 s.  c  o m

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:databaseName",
            "username", "password");
    if (connection != null) {
        System.out.println("Connected");
    } else {//from ww w .j a v a2 s.  c  om
        System.out.println("Failed to make connection!");
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");
    Statement st = con.createStatement();
    st.executeUpdate("CREATE DATABASE myDB");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");

    Statement st = con.createStatement();
    st.executeUpdate("ALTER TABLE mytable DROP col");
    System.out.println("Column is deleted successfully!");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");

    Statement st = con.createStatement();
    int n = st.executeUpdate("ALTER TABLE mytable DROP INDEX col");
    System.out.println("Query OK, " + n + " rows affected.");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");

    Statement st = con.createStatement();
    int n = st.executeUpdate("ALTER TABLE myTable CHANGE old_col  new_col int");
    System.out.println("Query OK, " + n + " rows affected");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");

    Statement st = con.createStatement();
    int n = st.executeUpdate("ALTER TABLE mytable ADD col int");
    System.out.println("Query OK, " + n + " rows affected");
}