聚沙成塔

-IDB功能单元测试示例

上一篇 / 下一篇  2013-05-06 20:13:16 / 个人分类:单元测试

package com.new.sapi.protocol;
import java.sql.*;
import java.util.*;
import java.io.IOException;
import org.junit.Before;
import org.junit.After;
import org.junit.Test;
import static org.junit.Assert;
import com.new.sapi.zxdb_access;

/*** 测试nt和linux系统下DB的连接功能***/
public void DBTest {
     zxdb_access zxdb = null;
 
@Before
public void setUp() throws Exception {
   zxdb = new zxdb_access();
        Thread.sleep(1000);
}
 
@After
public void tearDown() throws Exception {
}
 
 
@Test
public void testOracle() throws Exception {
     excuteQuery("134","select * from test"); 
}
 
void excuteQuery(String poolName, String sql) throws ZXYWException {
     Connection conn = null;
 Statement stmt = null;
 ResultSet rs = null;
 try {
     conn = zxdb.dbConn(poolName);
 stmt = zxdb.getStmt(conn);
 rs = zxdb.excuteQuery(sql,stmt);
 int rowCount = 0; 
 while(rs.next()) {
      rowCount++;
 }
 System.out.print("The total row count is " + rowCount);
 } catach (IOException e ){
     e.printStackTrace();
 } finally { 
     if(rs != null) {
 try {
rs.close();
 }  catach (IOException e ){
e.printStackTrace();
rs =null;
 }
 }
 if(stmt != null) {
 try {
stmt.close();
 }  catach (IOException e ){
e.printStackTrace();
stmt =null;
 }
  }
 if(conn != null) {
 try {
zxdb.dbfree(conn,poolName);
 }  catach (IOException e ){
e.printStackTrace();
 conn =null;
 }
 }
 }  
 
 
 
}
 
 
}

TAG: JUnit Junit JUNIT junit

 

评分:0

我来说两句

Open Toolbar