import java.sql.*;
public class JDBCExample {
public static void main( String args[] )
{
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.postgresql.Driver");
c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/testdb","alisher", "123456");
System.out.println("Opened database successfully");
stmt = c.createStatement();
String sql = "CREATE TABLE PHONEBOOK " +
"(ID INT PRIMARY KEY NOT NULL," +
" first_name VARCHAR(20) NOT NULL, " +
" last_name VARCHAR(20) NOT NULL, " +
" PHONE VARCHAR(20), " +
" EMAIL VARCHAR(50))";
stmt.executeUpdate(sql);
stmt.close();
c.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName()+": "+ e.getMessage() );
System.exit(0);
}
System.out.println("Table created successfully");
}
}
Class.forName("org.postgresql.Driver");
Connection c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres","postgres", "123456
");