import java.util.*; import java.sql.*; public class TestUpdateAPI { // Change the following values to meet your settings // --- public static String dblocation = "localhost:5432"; public static String dbname = "apitest"; public static String username = "saxtouri"; public static String password = ""; // --- public static void main(String[] args) { try { Class.forName("org.postgresql.Driver"); } catch(java.lang.ClassNotFoundException ex) { System.out.println(ex.getMessage()+ ": PostgreSQL driver is not found. \nCheck if the CLASSPATH variable contains the postgresql.jar path."); } //change dbURL to reflect the machine/port postmaster is running and //the name of your db String dbURL = "jdbc:postgresql://"+dblocation+"/"+dbname ; Properties info = new Properties(); info.setProperty("user", username); info.setProperty("password", password); try { Connection con = DriverManager.getConnection(dbURL, info); //begin the transaction con.setAutoCommit(false); Statement stmt = con.createStatement(); ResultSet rs = null; int retVal = -1; rs = stmt.executeQuery("select create_instance('www.culture.net/picasso132', '', 'Painter')"); if (rs.next()) { retVal = rs.getInt(1); } if (rs != null) rs.close(); if (retVal < 1) { System.out.println("Error code:"+retVal+"\nYou can use it to handle the error"); System.out.println("More one spi-api error codes can be found at:\nhttp://athena.ics.forth.gr:9090/RDF/updateAPI/errors.html"); return; } rs = stmt.executeQuery("select add_property('', 'paints', 'www.culture.net/picasso132', 'http://www.museum.es/guernica.jpg', 50)"); if (rs.next()) { retVal = rs.getInt(1); } if (rs != null) rs.close(); if (retVal < 1) { System.out.println("Error code:"+retVal+"\nYou can use it to handle the error"); System.out.println("More one spi-api error codes can be found at:\nhttp://athena.ics.forth.gr:9090/RDF/updateAPI/errors.html"); return; } rs = stmt.executeQuery("select update_property('', 'creates', 'www.culture.net/picasso132', '*', 'http://www.museum.es/woman.qti', 0, 50)"); if (rs.next()) { retVal = rs.getInt(1); } if (rs != null) rs.close(); if (retVal < 1) { System.out.println("Error code:"+retVal+"\nYou can use it to handle the error"); System.out.println("More one spi-api error codes can be found at:\nhttp://athena.ics.forth.gr:9090/RDF/updateAPI/errors.html"); return; } //commit the transaction con.commit(); System.out.println("Transaction committed!"); if (stmt != null) stmt.close(); } catch(SQLException ex) { System.out.println("SQLException: " + ex.getMessage()); ex.printStackTrace(); } } }