不知道大家对于数据库的查询的dao方法是怎么写的
项目之前有个select的查询方法的,需要的参数是一个sql语句,和where后面的条件值,自己最近写sql语句写烦躁了,写一个不用sql语句的方法看看,结果也不是很方便,而且灵活性也不高。
package com.xinnuo;import java.util.Vector;import com.xinnuo.core.dao.BaseDaoSupport;public class Sql extends BaseDaoSupport{//getRecord 为之前的方法 // table为表名,word为要查询的字段,where为条件语句,wherevalue为条件语句的值 public Vector select(String table ,String[] word ,String where,String[] wherevalue ) { String sql=""; Vector rs=new Vector(); sql="select "; for (int i = 0; i < word.length; i++) { sql += word[i]+","; } sql=sql.replaceAll(",$", ""); sql += " from "+table+" where "+where; try { rs=getRecord(sql,wherevalue); } catch (Exception e) { } System.out.println("sql===="+sql); System.out.println("rs==="+rs.toString()); return rs; } public static void main(String[] args) { String table="power"; String[] word={"Power_ID","Power_Name"}; String where="Power_ID=?"; String[] wherevalue={"16"}; Sql sql=new Sql(); sql.select(table,word,where,wherevalue); }}