sequoiadb四颗牙的搬运工,开发postgresql程序一样一样的

250750阅读 0评论2020-04-28 brjl
分类:Java


写java代码处理数据的过程跟普通的postgresql数据库一样的。

以下抄自官方培训  如有侵权,将删除

点击(此处)折叠或打开

  1. package com.sequoiadb.postgresql;


  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;


  6. public class Select {
  7.     private static String url = "jdbc:postgresql://127.0.0.1:5432/company";
  8.     private static String username = "sdbadmin";
  9.     private static String password = "";


  10.     public static void main(String[] args) throws SQLException {
  11.         select();
  12.     }


  13.     public static void select() throws SQLException {
  14.         PostgreSQLConnection pgConnection = new PostgreSQLConnection(url, username, password);
  15.         Connection connection = pgConnection.getConnection();
  16.         String sql = "select * from employee";
  17.         PreparedStatement psmt = connection.prepareStatement(sql);
  18.         ResultSet rs = psmt.executeQuery();
  19.         System.out.println("----------------------------------------------------------------------");
  20.         System.out.println("empno \t ename \t age");
  21.         System.out.println("----------------------------------------------------------------------");
  22.         while(rs.next()){
  23.             Integer empno = rs.getInt("empno");
  24.             String ename = rs.getString("ename");
  25.             String age = rs.getString("age");


  26.             System.out.println(empno + "\t" + ename + "\t" + age);
  27.         }
  28.         connection.close();
  29.     }
  30. }

修改

点击(此处)折叠或打开

  1. package com.sequoiadb.postgresql;

  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.SQLException;

  5. public class Update {
  6.     private static String url = "jdbc:postgresql://127.0.0.1:5432/company";
  7.     private static String username = "sdbadmin";
  8.     private static String password = "";

  9.     public static void main(String[] args) throws SQLException {
  10.         update();
  11.     }

  12.     public static void update() throws SQLException {
  13.         PostgreSQLConnection pgConnection = new PostgreSQLConnection(url, username, passwor
  14. d);
  15.         Connection connection = pgConnection.getConnection();
  16.         String sql = "update employee set age = ? where empno = ?";
  17.         PreparedStatement psmt = connection.prepareStatement(sql);
  18.         psmt.setInt(1, 41);
  19.         psmt.setInt(2, 10004);
  20.         psmt.execute();

  21.         connection.close();
  22.     }
  23. }

上一篇:sequoiadb四颗牙P 第五节 参考
下一篇:sequoiadb 四颗牙经典代码段 创建域、索引、看执行计划