Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connection con = null;
- try {
- Class.forName("org.postgresql.Driver");
- con = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5432/", "kyz", "rahasia");
- } catch (Exception e) {
- System.err.println(e);
- System.exit(0);
- }
- PreparedStatement pst = null;
- ResultSet rs = null;
- if (con != null) {
- try {
- pst = con.prepareStatement("SELECT columnfoo FROM mytable WHERE columnfoo = ?");
- pst.setString(1, "test2");
- //pst.setInt(1, 21314);
- rs = pst.executeQuery();
- while (rs.next()) {
- System.out.print("Column 1 returned ");
- System.out.println(rs.getString(1));
- }
- rs.close();
- pst.close();
- con.setAutoCommit(false);
- Statement st = con.createStatement();
- st.setFetchSize(3);
- rs = st.executeQuery("SELECT * FROM mytable");
- while (rs.next()) {
- System.out.print("a row was returned.");
- System.out.println(rs.getString(1));
- }
- rs.close();
- st.setFetchSize(0);
- rs = st.executeQuery("SELECT * FROM mytable");
- while (rs.next()) {
- System.out.print("many rows were returned.");
- System.out.println(rs.getString(1));
- }
- rs.close();
- st.close();
- st = con.createStatement();
- st.executeUpdate("INSERT INTO test VALUES(1)");
- } catch (Exception e) {
- System.err.println(e);
- System.exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement