实现高效易用的java操作mysql包装
2009-11-27 00:00:00 来源:WEB开发网包装定长参数数组
package dao;
public class FixedParameters implements Parameters {
private MySqlParameter[] parms;
private int ptr = 0;
public FixedParameters(int size){
parms = new MySqlParameter[size];
}
public void Add(MySqlParameter parm) {
parms[ptr] = parm;
ptr++;
}
public MySqlParameter[] getBuffer() {
return parms;
}
public int getLength() {
return parms.length;
}
public MySqlParameter getParameter(int i) {
return parms[i];
}
}
添加操作,这里包装地还不够好,没在调用部分把MySql专有方式隔离出去。懒得再写个继承关系了,将就一下把,呵呵
public int Add(TestBean test) throws SQLException{
String sql = "insert into TestTable (name) values (?);";
Database db = DatabaseManager.getMySqlDatabase();
Parameters parms = db.CreateFixedParms(1);
parms.Add(new MySqlParameter(DBType.String,0,test.getName()));
return db.ExecuteNoneQuery(sql, parms);
}
更多精彩
赞助商链接