DriverManager: getConnection(String url, String user, String password) : DriverManager « java.sql « Java by API






DriverManager: getConnection(String url, String user, String password)

 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class Main {
  public static void main(String[] args) throws Exception {
    setup();
  }

  static Connection conn;

  static Statement st;

  public static void setup() {
    try {
      // Step 1: Load the JDBC driver.
      Class.forName("org.hsqldb.jdbcDriver");
      System.out.println("Driver Loaded.");
      // Step 2: Establish the connection to the database.
      String url = "jdbc:hsqldb:data/tutorial";

      conn = DriverManager.getConnection(url, "sa", "");
      System.out.println("Got Connection.");

      st = conn.createStatement();
    } catch (Exception e) {
      System.err.println("Got an exception! ");
      e.printStackTrace();
      System.exit(0);
    }
  }
}

           
         
  








JDBCEnvironment.zip( 595 k)

Related examples in the same category

1.DriverManager: getConnection(String url) (jdbc:odbc:technical_library)
2.DriverManager: getConnection(String url, Properties info)
3.DriverManager: getDrivers()
4.DriverManager: registerDriver(Driver driver)
5.DriverManager: setLogWriter(PrintWriter out)