Connect to database

Sep 16 2009 Published by under Java

try {
  String url = "jdbc:mysql://localhost:3306/mydb";
  Class.forName ("com.mysql.jdbc.Driver").newInstance ();
  Connection conn = DriverManager.getConnection (url, user, pwd);
} catch (Exception e){
  System.out.println("Unable to establish connection " + e.getMessage());
}

MySQL:
URL : jdbc:mysql://myserver:port/mydb
DriverName – com.mysql.jdbc.Driver
Library Jar Download – http://dev.mysql.com/downloads/connector/j/5.1.html

Oracle:
URL : jdbc:oracle:thin:@myserver:1521:myinstance
DriverName – oracle.jdbc.driver.OracleDriver
Library Jar Download – http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc9201.html

Postgre:
URL : jdbc:postgresql://localhost/mydb
DriverName – org.postgresql.Driver
Library Jar Download – http://pdb.finkproject.org/pdb/package.php/postgresql-java

Sybase:
URL : jdbc:sybase:mydb:myserver:myport
DriverName – com.sybase.jdbc.SybDriver
Library Jar Download – http://www.sybase.com/detail_list?id=2912

No responses yet