Obje3tives:

  • Creating connection string
  • Refactoring :: Renaming the object.
  • Code: JavaApp2.txt
Create a New Project: Java Application.

Choose project type:

Naming the current Project:

Add a jar folder

 

 

 


package javaap2;
import java.sql.Connection;
import java.sql.DriverManager;

/**
*
* @author Manas
*/

public class JavaApp2 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
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");
}
}