用SimpleDataSource.getConnection返回java.sql.Connection,然后只能用jdbc的方法去增删改查数据库吗?我想用nutzDao去操作这个数据库改如何是好,可以根据这个SimpleDataSource new一个Dao吗???
8 回复
dataSource = new SimpleDataSource();
dataSource.setJdbcUrl("jdbc:gbase://172.16.1.205:5258/tjbb_cms");
dataSource.setUsername("gbase");
dataSource.setPassword("gbase20110531");
dataSource.setDriverClassName("com.gbase.jdbc.Driver");
dao = new NutDao(dataSource);
dao.insert(obj);
非Mvc环境? 建议用DaoUp类.
下面是暴力方法, 依然推荐直接用DaoUp类.
private static DataSource ds;
private static Dao dao;
protect static Dao dao() {
if (ds == null) {
ds = new SimpleDataSource();
// ...
}
if (dao == null)
dao = new NutDao(ds);
return dao;
}
@wendal
代码如下
SimpleDataSource dataSource = new SimpleDataSource();
dataSource.setJdbcUrl(db.getJdbcURL());
dataSource.setLoginTimeout(30);
dataSource.setPassword(db.getPassword());
dataSource.setUsername(db.getUsename());
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
return dataSource.getConnection();
报错如下:
不求操作,就是先校验下能否能连上数据库
2016-10-12 15:53:26,975 org.nutz.dao.impl.SimpleDataSource.<init>(SimpleDataSource.java:33) WARN - SimpleDataSource is NOT a Connection Pool, So it is slow but safe for debug/study
java.lang.RuntimeException: Not implement yet!
at org.nutz.lang.Lang.noImplement(Lang.java:111)
at org.nutz.dao.impl.SimpleDataSource.setLoginTimeout(SimpleDataSource.java:95)
at compareDB.service.CompareDBService.getConn(CompareDBService.java:49)
at compareDB.service.CompareDBService.addDB(CompareDBService.java:33)
at compareDB.module.CompareDBModule.index(CompareDBModule.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
添加回复
请先登陆