Java数据库处理的方法库DBUtil

更新时间:2023-06-08 19:49:08 阅读: 评论:0

Java数据库处理的方法库DBUtil
20100716 13:28  |  分类:测试开发 刚毅
1.postgres数据库的lect操作,返回lect后返回的第一行数据松脂的意思,返回类型为string,若要返回int,只需将getString改为getInt
 public static String PgDBSelect(String sql) throws ClassNotFoundException, SQLException{
just for fun  String dbURL=jdbc:postgresql://172.16.4.25:5432/skyups;
  String dbur=***;
  String dbpasswd=***;
  Class.forName(org.postgresql.Driver);
  Connection conn = Connection(dbURL,dbur,dbpasswd);
  Statement stmt = ateStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = uteQuery(sql);
    rs.next();
    String String(1);
    rs.clo();
    stmt.clo();
    conn.clo();extensive
    return value;
 }
2.postgres数据的执行操作,可执行instertdeleteupdate等操作,不返回数据
 public static void PgDBUpdate(String sql) throws ClassNotFoundException, SQLException{eblin
  String dbURL=jdbc:postgresql://172.16.4.25:5432/skyups;
  String dbur=***;
  String dbpasswd=***hardest;
  Class.forName(org.postgresql.Driverdarkblue);
  Connection conn = Connection(dbURL,dbur,dbpasswd);
hash hash  Statement stmt = ateStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    uteUpdate(sql);
    stmt.clo();
    conn.clo();
 }
3. oracle数据库的lect操作,返回lect后返回的第一行数据,若要返回int,只需将getString改为getInt
 public static String OracleDBSelect(String sql) throws ClassNotFoundException, SQLException{
  String dbURL=jdbc:oracle:thin:@172.16.4.21:1521:skytest;
  String dbur=***;
pets3成绩查询  String dbpasswd=***;
  Class.forName(oracle.jdbc.OracleDriver);
  Connection conn = Connection(dbURL,dbur,dbpasswd);
  Statement stmt = ateStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = uteQuery(sql);
    rs.next();
    int String(1);
    rs.clo();
    stmt.clo();
    conn.clo();
    return expbalance;
 }
4.oralce数据的执行操作,可执行instertdeleteupdate等操作,不返回数据
 public static void OracleDBUpdate(String sql) throws ClassNotFoundException, SQLException{
  String dbURL=jdbc:oracle:thin:@172.16.4.21:1521:skytest;
  String dbur=***;
  String dbpasswd=***;
  Class.forName(oracle.jdbc.OracleDriver);
  Connection conn = Connection(dbURL,dbur,dbpasswd);
  Statement stmt = ateStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    uteUpdate(sql);
    stmt.clo();
    conn.clo();
 }
5.Cassandra非关系型数据库的操作,包括deleteinrtread等。
六级阅读分值 public static void CassandraRemove(String USkyid)throws IllegalStateException, PoolExhaustedException,Exception {
  CassandraClientPool pool = ();
  CassandraClient client = pool.borrowClient(172.16.4.244, 9160);
  try{
        Keyspace keyspace = Keyspace(skyups);
        ColumnPath columnPath = new ColumnPath();
        columnPath.tColumn_family(ud toUrInfo); 
        //delete
        ve(USkyid, columnPath);
        /*
        // read
        Column col = Column(value, columnPath);
        System.out.println(Read from cassandra: + Value()));
        // inrt
        keyspace.inrt(key, columnPath, bytes(value));
        */
  } finally{
  &leaClient(client); 
   }
  }
 
利用方法库执行一次完整的junit测试举例:
step1.设置一条用户信息,包括所有字段参数。step2:再发送一条设置信息,其中用户的出生日期为空。step3:删除这条用户信息,恢复环境。
@Before
 public void tUp() throws Exception {
  Socket socket=new Socket(ServerIP,Port);
  DataOutputStream dos=new OutputStream());
  DataInputStream dis=new InputStream());
  byte[] resp=new byte[1024];
 
  System.out.println(StartUp:预置测试环境,初始化设置1条用户信息);
  byte[] turinfomsg1=PackMsg.SetUrInfoMsg(USkyid, UUrName, UNickname, URealName, USex, UBirthday, UAnimals, UStar, UBlood, UMarried, UPortraitId, UDefinePortrait, UCountry, UProvince, UCity, UHometown, ULongitude, ULatitude, USignature, UDesc, UEmail, UEmailChecked, UMobile, UMobileChecked, UTelephone, UVocation, USchoolGraduated, UPrivacy, UIdCardNo,HasPic);
  dos.write(turinfomsg1);ad(resp);
  Thread.sleep(1000);
  dos.flush();dis.clo();socket.clo();
 }
 @Test
 public void testSetUrInfo_Edit_BirthDay() throws Exception {
  Socket socket=new Socket(ServerIP,Port);
  DataOutputStream dos=new OutputStream());
  DataInputStream dis=new InputStream());
  byte[] resp=new byte[1024]; 
 
  System.out.println(Ca1:执行测试,对出生日期为空字符串的逻辑进行修正,若为空字符串,则将原有的出生日期清空,设置为默认值1800-01-01);
  String UBirthday= ;
  byte[] turinfomsg1=PackMsg.SetUrInfoMsg_Birthday(USkyid, UBirthday);
  dos.write(turinfomsg1);ad(resp);
  int respcode2=ByteUtil.bytes2int2(resp, 40, 4);
  System.out.println(Respcode:+respcode2);
  asrtEquals (Respcode Error!,200,respcode2);
  Thread.sleep(1000);
  asrtEquals (Birthday Error!,1800-01-01,DBUtil.PgDBSelect(lect birthday from skyups.tbl_ups_ur_info where skyid=+USkyid));
  dos.flush();dis.clo();socket.clo();
 }

本文发布于:2023-06-08 19:49:08,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/138447.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:执行   用户   信息   设置   操作   出生日期   数据
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图