NutzCN Logo
问答 oracle和sqlite3连接池配置
发布于 2287天前 作者 wx_jjn2ia9qvotogktb45bf 2469 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

将nutz框架的原数据(oracle)连接配置改为sqlite3作为nutz运行的数据库

#sqlite3
db.name=liuliu
db.url=jdbc:sqlite:E:/STUDY/NutzWk-modular/sqlite/liuliu.db
db.username=scott
db.password=root

报错

org.nutz.castor.FailToCastObjectException: Fail to cast from <java.lang.String> to <java.sql.Driver> for {liuliu}
	at org.nutz.castor.Castors.cast(Castors.java:263)
	at org.nutz.castor.Castors.castTo(Castors.java:317)
	at org.nutz.lang.inject.InjectBySetter.inject(InjectBySetter.java:46)
	at org.nutz.ioc.impl.PropertiesProxy.make(PropertiesProxy.java:400)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.nutz.lang.Invoking$DefaultInvoker.invoke(Invoking.java:47)
	at org.nutz.lang.Invoking.invoke(Invoking.java:192)
	at org.nutz.lang.Mirror.invoke(Mirror.java:1132)
	at org.nutz.ioc.impl.ObjectMakerImpl$1.born(ObjectMakerImpl.java:80)
	at org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:78)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:117)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:64)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:64)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:161)
	at cn.wizzer.app.web.commons.filter.TokenFilter.<init>(TokenFilter.java:22)
	at cn.wizzer.app.web.commons.filter.TokenFilter$FC$03a2a03dc16e33351501963d0b3a906c.invoke(TokenFilter.java)
	at org.nutz.lang.born.AbstractConstructorBorning.call(AbstractConstructorBorning.java:25)
	at org.nutz.lang.born.EmptyArgsConstructorBorning.born(EmptyArgsConstructorBorning.java:14)
	at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60)
	at org.nutz.lang.Mirror.born(Mirror.java:1022)
	at org.nutz.mvc.impl.Loadings.evalObj(Loadings.java:336)
	at org.nutz.mvc.impl.processor.AbstractProcessor.evalObj(AbstractProcessor.java:48)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.init(ActionFiltersProcessor.java:32)
	at org.nutz.mvc.impl.NutActionChainMaker.eval(NutActionChainMaker.java:38)
	at org.nutz.mvc.impl.UrlMappingImpl.add(UrlMappingImpl.java:54)
	at org.nutz.mvc.impl.NutLoading.evalUrlMapping(NutLoading.java:205)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:108)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:91)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:69)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4700)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5340)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:753)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:729)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
	at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1696)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:484)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:433)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
	at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
	at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
	at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)
	at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
	at sun.rmi.transport.Transport$1.run(Transport.java:200)
	at sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.nutz.lang.born.BorningException: Fail to born or cast to 'java.sql.Driver'
 by args: [@(liuliu)]
 because: No suitable Constructor or Factory Method!!
	at org.nutz.lang.Mirror.born(Mirror.java:1020)
	at org.nutz.castor.castor.String2Object.cast(String2Object.java:16)
	at org.nutz.castor.castor.String2Object.cast(String2Object.java:9)
	at org.nutz.castor.Castors.cast(Castors.java:253)
	... 86 more

33 回复

db.name是什么东西,没配过这个吧

@wendal 就是像oracle一样 把连接属性改一下,

db.name=nutzwk
db.url=jdbc:oracle:thin:@//127.0.0.1:1521/orcl
db.username=scott
db.password=root
db.validationQuery=select 1 from dual
db.maxActive=100
db.testWhileIdle=true
db.filters=mergeStat
db.connectionProperties=druid.stat.slowSqlMillis=2000

sqlite3

db.name=liuliu
db.url=jdbc:sqlite:E:/STUDY/NutzWk-modular/sqlite/liuliu.db
db.username=scott
db.password=root

只有这些?

@wendal
LongNames=0
Timeout=1000
NoTXN=0
SyncPragma=NORMAL
StepAPI=0
这些属性在nutz下是灰色的,不生效

你贴的是全部配置了? 是不是改过dao.js?

@wendal 就改了dao.json 和上面的那些配置

var ioc = {
		conf : {
			type : "org.nutz.ioc.impl.PropertiesProxy",
			fields : {
				paths : ["config/custom/sqlite3.properties"]
			}
		},
	    dataSource : {
			factory : "$conf#make",
			args : ["com.alibaba.druid.pool.DruidDataSource", "db."],
	        type : "com.alibaba.druid.pool.DruidDataSource",
	        events : {
	        	create : "init",
	            depose : 'close'
	        }
	    },
		dao : {
			type : "org.nutz.dao.impl.NutDao",
			args : [{refer:"dataSource"}],
		}
};

不要改dao.json

@wendal 即使没有修改也是同样的错误

那就还原到oracle能跑的配置

你这是nutzwk的代码吧?用sqlite3跑不起来的,可能性基本上等于0

@wendal 已经改回去了,我想用sqlite3写一个类似于便携式数据库的文件,那没有方法能用sqlite3连接上nutz框架?谢谢

@wendal 是的,在Git上找的,有没有解决方法呢?

是要整个系统只连sqlite3,还是额外连个sqlite3

用h2database试试吧

@wendal 额外配置一个sqlite3,随身携带,用的时候,直接配置一下属性

来自炫酷的 NutzCN

@wendal 本质上我想做一个便携式的数据库,在nutz框架下,存储空间地理信息SDO_等字段,但是空间字段对于数据库是有限制的,所以转成字符串的形式存储,读出来我在给它转换成我想要的形式,这个数据不是放在缓存中,最好就是一个本地的db文件,使用的时候额外配置一下连接属性就好,能够随时使用。

做个dataSource2和dao2 ,然后配置信息用db2.开头

http://nutzam.com/core/dao/multiple_datasource.html

var ioc = {
		conf : {
			type : "org.nutz.ioc.impl.PropertiesProxy",
			fields : {
				paths : ["config/custom/"]
			}
		},
	        dataSource : {
			factory : "$conf#make",
			args : ["com.alibaba.druid.pool.DruidDataSource", "db."],
	                type : "com.alibaba.druid.pool.DruidDataSource",
	                events : {
	        	create : "init",
	                depose : 'close'
	           }
	        },
		dao : {
			type : "org.nutz.dao.impl.NutDao",
			args : [{refer:"dataSource"}],
		},
	        dataSource2 : {
			factory : "$conf#make",
			args : ["com.alibaba.druid.pool.DruidDataSource", "db2."],
	                type : "com.alibaba.druid.pool.DruidDataSource",
	                events : {
	        	create : "init",
	                depose : 'close'
	           }
	        },
		dao2 : {
			type : "org.nutz.dao.impl.NutDao",
			args : [{refer:"dataSource2"}],
		},
};

@wendal

org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (no such table: dual)
	at org.sqlite.core.DB.newSQLException(DB.java:909)
	at org.sqlite.core.DB.newSQLException(DB.java:921)
	at org.sqlite.core.DB.throwex(DB.java:886)
	at org.sqlite.core.NativeDB.prepare_utf8(Native Method)
	at org.sqlite.core.NativeDB.prepare(NativeDB.java:127)
	at org.sqlite.core.DB.prepare(DB.java:227)
	at org.sqlite.jdbc3.JDBC3Statement.executeQuery(JDBC3Statement.java:81)
	at com.alibaba.druid.filter.FilterChainImpl.statement_executeQuery(FilterChainImpl.java:2473)
	at com.alibaba.druid.filter.FilterAdapter.statement_executeQuery(FilterAdapter.java:2503)
	at com.alibaba.druid.filter.FilterEventAdapter.statement_executeQuery(FilterEventAdapter.java:302)
	at com.alibaba.druid.filter.FilterChainImpl.statement_executeQuery(FilterChainImpl.java:2470)
	at com.alibaba.druid.proxy.jdbc.StatementProxyImpl.executeQuery(StatementProxyImpl.java:221)
	at com.alibaba.druid.pool.DruidAbstractDataSource.validateConnection(DruidAbstractDataSource.java:1331)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1588)
	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2466)

报这个错

你改了什么,贴出来

@wendal 加了一个db2.properties

#sqlite3
db.name=liuliu
db.url=jdbc:sqlite:E:/STUDY/NutzWk-modular/sqlite/liuliu.db
db.username=scott
db.password=root

同时在json中加入
dataSource2 : {
factory : "$conf#make",
args : ["com.alibaba.druid.pool.DruidDataSource", "db2."],
type : "com.alibaba.druid.pool.DruidDataSource",
events : {
create : "init",
depose : 'close'
}
},
dao2 : {
type : "org.nutz.dao.impl.NutDao",
args : [{refer:"dataSource2"}],
},

用 "插入代码" 按钮重新发一次

db2.properties

#sqlite3
db.name=liuliu
db.url=jdbc:sqlite:E:/STUDY/NutzWk-modular/sqlite/liuliu.db
db.username=scott
db.password=root

dao.json 中加入

dataSource2 : {
		factory : "$conf#make",
		args : ["com.alibaba.druid.pool.DruidDataSource", "db2."],
		type : "com.alibaba.druid.pool.DruidDataSource",
		events : {
			create : "init",
			depose : 'close'
		}
	},
	dao2 : {
		type : "org.nutz.dao.impl.NutDao",
		args : [{refer:"dataSource2"}],
	},
#sqlite3
db2.name=liuliu
db2.url=jdbc:sqlite:E:/STUDY/NutzWk-modular/sqlite/liuliu.db
db2.username=scott
db2.password=root

用的时候

@Inject
private Dao dao2;

@wendal 改完db2后可以用,
测了dao2.exits("tablename")是可以用的

System.out.println(dao2);
     Boolean a = dao2.exists("dili_p");

返回值存在,是true
万分感谢 wendal

@wendal 可以将sqlite3作为系统运行的数据库
但是要注释// initSysTask(config, dao); 这个方法

initSysData(config, dao);
            // 初始化系统变量
            initSysSetting(config, dao);
            // 初始化定时任务
           initSysTask(config, dao);//注释这个 
            // 初始化自定义路由
            initSysRoute(config, dao);
            // 初始化热插拔插件
            initSysPlugin(config, dao);

其中,quartzManager.clear();//启动时清除任务(不影响集群任务) 这句话出错了,打断点显示的

 Sys_task task = new Sys_task();
            task.setDisabled(true);
            task.setName("测试任务");
            task.setJobClass("cn.wizzer.app.web.commons.quartz.job.TestJob");
            task.setCron("*/5 * * * * ?");
            task.setData("{\"hi\":\"Wechat:wizzer | send red packets of support,thank u\"}");
            task.setNote("微信号:wizzer | 欢迎发送红包以示支持,多谢。。");
            dao.insert(task);
        }
        QuartzManager quartzManager = config.getIoc().get(QuartzManager.class);
        quartzManager.clear();//启动时清除任务(不影响集群任务)    出错处
        List<Sys_task> taskList = dao.query(Sys_task.class, Cnd.where("disabled", "=", false));
        for (Sys_task sysTask : taskList) {
            try {
                QuartzJob qj = new QuartzJob();
                qj.setJobName(sysTask.getId());
                qj.setJobGroup(sysTask.getId());
                qj.setClassName(sysTask.getJobClass());
                qj.setCron(sysTask.getCron());
                qj.setComment(sysTask.getNote());
                qj.setDataMap(sysTask.getData());
                quartzManager.add(qj);
            } catch (Exception e) {
                log.error(e.getMessage());

至于具体怎么出错 我就不知道了

这是个奇迹。。。

想起来,quartz.properties需要配对应别名

能简单说明一下吗?
该产生的表都产生了,别的基本都可以使用

数据库模式的类型

具体改哪个?

#==============================================================    
#Configure Main Scheduler Properties    
#==============================================================     
org.quartz.scheduler.instanceName = defaultScheduler
org.quartz.scheduler.instanceId = AUTO

#==============================================================    
#Configure JobStore     isClustered=启用集群模式
#==============================================================   
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
#org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
#org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.oracle.OracleDelegate
#Other delegates can see: http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/tutorial-lesson-09.html
org.quartz.jobStore.dataSource=myDS
org.quartz.jobStore.tablePrefix = SYS_QRTZ_
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 20000
org.quartz.jobStore.maxMisfiresToHandleAtATime = 120
org.quartz.jobStore.misfireThreshold = 120000
org.quartz.jobStore.txIsolationLevelSerializable = false

#==============================================================    
#Configure ThreadPool    
#==============================================================   
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 2
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true

#==============================================================  
#Skip Check Update  
#update:true  
#not update:false  
#==============================================================  
org.quartz.scheduler.skipUpdateCheck = true

#============================================================================     
# Configure Plugins      
#============================================================================        
org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingJobHistoryPlugin
org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin
org.quartz.plugin.shutdownhook.cleanShutdown = true
#============================================================================
# NutDao dataSource
#============================================================================
org.quartz.dataSource.myDS.connectionProvider.class = org.nutz.integration.quartz.NutConnectionProvider

driverDelegateClass 下面有链接

添加回复
请先登陆
回到顶部