測試分類
第一步
去Junit主頁(http://www
第二步
假如目錄是c
第三步
實現自己的TEST計劃
package junitsamples; import java
sql *;
import javaio *; public class MyBean{
Statement stmt=null;
ResultSet rs=null;
Connection conn=null;
String result=null;
public String con(){ //初始化數據庫
try{
ClassforName( org gjt mm mysql Driver ) newInstance();
String url =jdbc:mysql:// /weboa?user=root&password= ;
conn= DriverManagergetConnection(url);
returnConnection Success! ;
}
catch(Exception e){
Systemout println(e);
returnConnection Error! ;
}
}
public String gogo(String lmdm){ //查詢數據庫
try{
stmt=conncreateStatement();
String sql=select * from TB_LM where N_LMDM= +lmdm+ ;
rs=stmtexecuteQuery(sql); //執行查詢
while (rsnext()){
result=rsgetString( N_SJID );
}
}
catch(Exception e){
result=etoString();
}
finally { //關閉JDBC資源
if(rs != null) try { rsclose(); } catch(SQLException ex)
{ exprintStackTrace(); }
if(conn != null) try { connclose(); } catch(SQLException ex)
{ exprintStackTrace(); }
}
return result;
}
}
[
From:http://tw.wingwit.com/Article/program/Java/ky/201311/29242.html