import java.sql.*; public class ZTest { public static void main(String args[]) throws Exception { Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5750/jurka","jurka",""); setupDB(conn); PreparedStatement pstmt = conn.prepareStatement("SELECT a FROM thetable WHERE a LIKE ? "); pstmt.setString(1,"z%"); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { System.out.println(rs.getString(1)); } rs.close(); pstmt.close(); conn.close(); } private static void setupDB(Connection conn) throws SQLException { Statement stmt = conn.createStatement(); try { stmt.executeUpdate("DROP TABLE thetable"); } catch (SQLException sqle) { conn.rollback(); } stmt.executeUpdate("CREATE TABLE thetable(a text)"); stmt.executeUpdate("INSERT INTO thetable VALUES ('hello')"); } }