import java.io.*; import java.sql.*; import java.text.*; public class dbt { Connection db; Statement st; public dbt(String args[]) throws ClassNotFoundException, FileNotFoundException, IOException, SQLException { Class.forName("postgresql.Driver"); db = DriverManager.getConnection("jdbc:postgresql:contabil", "postgres", "postgres"); st = db.createStatement(); cleanup(); doexample(); //cleanup(); System.out.println("Now closing the connection"); st.close(); db.close(); } public void cleanup() { try { st.executeUpdate("drop table teste"); } catch(Exception ex) { // We ignore any errors here } } public void doexample() throws SQLException { System.out.println("\nRunning tests:"); st.executeUpdate("create table teste (id int2,nume text)"); st.executeUpdate("insert into teste values (1,'vasile')"); st.executeUpdate("insert into teste values (2,'ion')"); st.executeUpdate("insert into teste values (3,'gelu')"); System.out.println("performing a query"); //ResultSet rs = st.executeQuery("select * from teste"); System.out.println("Facem selectul ..."); ResultSet rs = st.executeQuery("select nume from teste"); System.out.println("L-am facut"); if(rs!=null) { while(rs.next()) { //int a = rs.getInt("id"); String b = rs.getString(1); //System.out.println(" id="+a+" nume="+b); System.out.println("nume="+b); } rs.close(); } } public static void main(String args[]) { // Now run the tests try { dbt test = new dbt(args); } catch(Exception ex) { System.err.println("Exception caught.\n"+ex); ex.printStackTrace(); } } }