HaishenDB第一个例子
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package com.haishen.test.bean;import com.haishen.db.api.IPreparedStatementCallBack;import com.haishen.db.bean.AbstractBean;import com.haishen.db.bean.TableMetadata;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;/** * * @author hicen */public class PersonTest extends AbstractBean { private final static PersonTest.Table tableTmp = new PersonTest.Table(); public static class Table extends PersonTestTable { } public PersonTest() { super(tableTmp); } public void setId(final String id) { this.id = id; IPreparedStatementCallBack pscb = new IPreparedStatementCallBack() { @Override public void setValue(PreparedStatement psmt, int pintIndex) throws SQLException { psmt.setString(pintIndex, id); } }; this.put(tableTmp.id.getName(), pscb); } public void setName(final String name) { this.name = name; IPreparedStatementCallBack pscb = new IPreparedStatementCallBack() { @Override public void setValue(PreparedStatement psmt, int pintIndex) throws SQLException { psmt.setString(pintIndex, name); } }; this.put(tableTmp.name.getName(), pscb); } public void setAge(final int age) { this.age = age; IPreparedStatementCallBack pscb = new IPreparedStatementCallBack() { @Override public void setValue(PreparedStatement psmt, int pintIndex) throws SQLException { psmt.setInt(pintIndex, age); } }; this.put(tableTmp.age.getName(), pscb); } @Override public void iniFromDB(ResultSet rs) throws SQLException { this.id = rs.getString(tableTmp.id.getName()); this.name = rs.getString(tableTmp.name.getName()); this.age = rs.getInt(tableTmp.age.getName()); } @Override public String getIdName() { return tableTmp.id.getFullName(); } @Override public String getIdValue() { return this.id; } public String getId() { return id; } public String getName() { return name; } public int getAge() { return age; } private String id; private String name; private int age;}class PersonTestTable extends TableMetadata { public PersonTestTable() { super("t_person"); } public StringCol id = new StringCol("Id"); public StringCol name = new StringCol("Name"); public IntegerCol age = new IntegerCol("Age"); }?
?
?
?
?