private String env="java:comp/env/jdbc/TestDB"; public String getEnv(){return env;} public void setEnv(String env){this.env=env;} public DataSource getDataSource(){//取得数据源(连结池) try{
Context ictx=new InitalContext();
ds=(DataSource)ictx.lookup(env);
}catch(Exception ignore){
//some debug codes
} return ds; } public Connection getConnection(){//取得数据库连结 if(ds==null)ds=getDataSource();
try{
if(conn==null)conn=ds.getConnection();
}catch(Exception ignore){
//some debug codes
} return conn; } } //存储 package upload.example1;
import java.sql.*;
public class DBStore(){
public static String ISFILEEXIST="select count(*) from TestTable where lsh=?";
public static String INSERTFILE="insert into TestTable (lsh)values(?)";
public static String UPDATEFILE="update TestTable set nr=? where lsh=?";