happyjdbc
项目地址:https://github.com/yuancihang/happyjdbc
简化jdbc操作,提供更现代化的api, 支持分库分表
public class DataExample {
public static void main(String[] args) throws SQLException {
DataAccess.getInstance().addDataSource("local", buildDataSource());
sampleShare();
}
private static DataSource buildDataSource() throws SQLException{
return new DataSourceBuilder()
.setDbName("my")
.setHost("localhost")
.setPort(3306)
.setUsername("root")
.setPassword("123456")
.build();
}
public static void sampleUniq() throws SQLException{
int result = DataAccess.getInstance()
.execute(new OpUniq("local", "select c2 from t1 where c1=?", null, 1){})
.uniqResult();
System.err.println(result);
T1 t1 = DataAccess.getInstance()
.execute(new OpUniq("local", "select * from t1 where c1=?", null, 1){})
.uniqResult();
System.err.println(t1);
Map map = DataAccess.getInstance()
.execute(new OpUniq
maven
com.github.yuancihang
happyjdbc
1.2
gradle
compile 'com.github.yuancihang:happyjdbc:1.2'