JDBC_eclipse platform1.htm
  • Importing Jars : Eclipse
    •  Right click on your project
    • Choose property
    • Choose Java build path
    • Choose add external JARS.. and select the location to the JDBC driver.
  • // Class.forName("org.postgresql.Driver");
  • c = DriverManager
    .getConnection("jdbc:postgresql://localhost:5432/postgres",
    "postgres", "postgre_manas9");
Steps:

Java Build Path>> Libraries:

Select and click on External jars:

Added  PostgreSQL jars to this template as an external jars:

Same add MySQL drivers:

Code Used :

package manas.com;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;

public class JavaTemplate1 {

public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello world");
Connection c = null;
try {
//Class.forName("org.postgresql.Driver");
c = DriverManager
.getConnection("jdbc:postgresql://localhost:5432/postgres",
"postgres", "postgre_manas9");
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getClass().getName()+": "+e.getMessage());
System.exit(0);
}
System.out.println("Connected to database successfully");
}
}


 

Output