我的需求是:
数据库1使用dao1,
数据库2使用dao2,
数据库1查询出来 的数据 处理后需要 立即插入到 数据库2。
就是一个数据迁移的工具。不打算使用IOC容器。
我在尝试new2个NutDao时出现报错。
public static void main(String[] args) {
final SimpleDataSource ds1 = createDataSources("jdbc:mysql://192.168.0.19:3306/db1?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull"
, "root", "root");
final SimpleDataSource ds2 = createDataSources("jdbc:mysql://192.168.0.19:3306/db2?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull\n"
, "root", "root");
Dao dao1 = new NutDao(ds1);
Dao dao2 = new NutDao(ds2);
}
public static SimpleDataSource createDataSources(String url,String user,String pwd){
SimpleDataSource dataSource = new SimpleDataSource();
dataSource.setJdbcUrl(url);
dataSource.setUsername(user);
dataSource.setPassword(pwd);
return dataSource;
}
Exception in thread "main" java.lang.RuntimeException: java.sql.SQLException: The connection property 'zeroDateTimeBehavior' only accepts values of the form: 'exception', 'round' or 'convertToNull'. The value 'convertToNull
' is not in this set.
at org.nutz.lang.Lang.wrapThrow(Lang.java:187)
at org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:116)
at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:187)
at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:178)
at org.nutz.dao.impl.NutDao.<init>(NutDao.java:108)
at com.example.demo.DemoApplication.main(DemoApplication.java:16)
Caused by: java.sql.SQLException: The connection property 'zeroDateTimeBehavior' only accepts values of the form: 'exception', 'round' or 'convertToNull'. The value 'convertToNull
' is not in this set.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861)
at com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.validateStringValues(ConnectionPropertiesImpl.java:314)
at com.mysql.jdbc.ConnectionPropertiesImpl$StringConnectionProperty.initializeFrom(ConnectionPropertiesImpl.java:575)
at com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.initializeFrom(ConnectionPropertiesImpl.java:216)
at com.mysql.jdbc.ConnectionPropertiesImpl.initializeProperties(ConnectionPropertiesImpl.java:2538)
at com.mysql.jdbc.ConnectionImpl.initializeDriverProperties(ConnectionImpl.java:3143)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:762)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at org.nutz.dao.impl.SimpleDataSource.getConnection(SimpleDataSource.java:43)
at org.nutz.trans.Trans.getConnectionAuto(Trans.java:263)
at org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:109)
... 4 more