| Create_Table_Dept4.htm |
| Existing tables in ogsdemo1 data base.
|
| Add jar to the existing libraries
|
| Using NetBean 7.3.1
Builds:
|
![]() pgAdmin confirms the new table added to the list.
|
Script: Code :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package template1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Manas9
*/
public class Template1 {
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
// TODO code application logic here
System.out.println("main block executing ");
Connection con = null; Statement st = null;
//
String url = "jdbc:postgresql://localhost/pgsdemo1";
String user = "manas237"; String password = "pwmanas237";
System.out.println("host user and password ---passd through ");
try {
con = DriverManager.getConnection(url, user, password);
st = con.createStatement();
System.out.println("Data Base connected ");
String sql = "CREATE TABLE DEPT5"+
"(DEPTNO NUMERIC(2) CONSTRAINT PK_DEPT5 PRIMARY KEY,"+
"DNAME VARCHAR(14) ," +
"LOC VARCHAR(13) )" ;
System.out.println("Table Created ") ;
st.executeUpdate(sql);
st.close(); con.close();
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(Template1.class.getName());
lgr.log(Level.SEVERE, ex.getMessage(), ex);
} finally {
try {
if (st != null) {
st.close();
System.out.println("Statement createStament... closed");
}
if (con != null) {
con.close();
System.out.println("DB connection... closed");
}
System.out.println("finally block executing ");
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(Template1.class.getName());
lgr.log(Level.WARNING, ex.getMessage(), ex);
}
}
// main block ends here
}
}
|