1、配置xml动态表文件,配置数据连接和用户密码。
2、在java里加载解析xml,取数据库相关信息,链接数据库,拼接sql,我这里用jd水瑞侮瑜bc链接,查询表数据,并返回。下面我列出主要的代码供参考,具体解析xml可以通过多种方法,这里就不列了。new oracle.jdbc.driver.OracleDriver(); String spath= this.getRequest().getRealPath("/"); spath=spath+"\\dbcofig\\oildbconf.xml"; List<Map> atxt = new ArrayList<Map>(); //从配置文件里取配置的表名 try { GetTablenames(spath); List<String> depttree=getoiltree(this.tableen,this.tablezh,oilbh); //默认查询第一个表的数据 //取表字段 Getcolsinfo(spath,tableen.get(0)); Getdbinfo(spath); //取数据库信息 Class.forName(this.driverClass); con = DriverManager.getConnection(this.jdbcUrl,this.user,this.pwd); stmt = con.createStatement(); //拼sql选择字段 String strcol=""; for(int i=0;i<colen.size();i++){ if(i==0){ strcol=colen.get(i); }else{ strcol=strcol+","+colen.get(i); } } String sqlstr="select "+strcol+" from "+tableen.get(0) +" where jh= '"+oilbh+"' order by "+colen.get(0); result = stmt.executeQuery(sqlstr); //执行SQL 语句,查询数据库 while (result.next()){ Map map = new LinkedHashMap(); for(int j=0;j<colen.size();j++){ map.put(colen.get(j),result.getObject(j+1)); } atxt.add(map); } setAttr("result",atxt);//保存查询结果 result.close(); con.close();