我是Android Studio和Android开发的新手,我在使用游标将多个参数传入sqlite时遇到问题 我有以下内容:
Cursor cursor = DB.rawQuery("select _id, BookingType as bookingType from " + table + " where " + SqLiteTableData.TableStructure.KEY_BOOKING_DATE+" = ? AND " + SqLiteTableData.TableStructure.KEY_BOOKING_TIME+ " = ? " , new String[]{a, b });
在调试器中显示以下内容:
SQLiteDirectCursorDriver: select _id, BookingType as bookingType from Bookings where BookingDate = ? AND BookingTime = ?
未传递参数
我已经花了很多年的时间,并查看其他帖子,如 How to pass two or more selection argument in "query" method
android sqlite query with multiple where
但无法让它发挥作用
任何帮助表示赞赏
答案 0 :(得分:0)
您的代码是正确的。参数传递正确。
调试器不显示参数值,因为它们永远不会合并到SQL命令 text 中。数据库将在稍后阶段处理参数。
答案 1 :(得分:0)
我建议你可以使用java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
org.jboss.logging.Slf4jLoggerProvider.getLogger(Slf4jLoggerProvider.java:29)
org.jboss.logging.LoggerProviders.find(LoggerProviders.java:33)
org.jboss.logging.LoggerProviders.<clinit>(LoggerProviders.java:28)
org.jboss.logging.Logger.getLogger(Logger.java:2163)
org.jboss.logging.Logger$1.run(Logger.java:2263)
java.security.AccessController.doPrivileged(Native Method)
org.jboss.logging.Logger.getMessageLogger(Logger.java:2227)
org.jboss.logging.Logger.getMessageLogger(Logger.java:2214)
org.hibernate.cfg.Configuration.<clinit>(Configuration.java:192)
org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:324)
com.cherry.oauth.multitenant.connection.provider.MultiTenantConnectionProvider.getSessionFactory(MultiTenantConnectionProvider.java:80)
com.cherry.oauth.multitenant.dbhandler.TenantSesionFactory.getSession(TenantSesionFactory.java:49)
com.cherry.oauth.service.MyAuthServiceImpl.authenticate(MyAuthServiceImpl.java:89)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:483)
com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ObjectOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:258)
com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.catalina.filters.CorsFilter.handleSimpleCORS(CorsFilter.java:301)
org.apache.catalina.filters.CorsFilter.doFilter(CorsFilter.java:169)
</pre><p><b>root cause</b></p><pre>java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
org.jboss.logging.Slf4jLoggerProvider.getLogger(Slf4jLoggerProvider.java:29)
org.jboss.logging.LoggerProviders.find(LoggerProviders.java:33)
org.jboss.logging.LoggerProviders.<clinit>(LoggerProviders.java:28)
org.jboss.logging.Logger.getLogger(Logger.java:2163)
org.jboss.logging.Logger$1.run(Logger.java:2263)
java.security.AccessController.doPrivileged(Native Method)
org.jboss.logging.Logger.getMessageLogger(Logger.java:2227)
org.jboss.logging.Logger.getMessageLogger(Logger.java:2214)
org.hibernate.cfg.Configuration.<clinit>(Configuration.java:192)
org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:324)
com.cherry.oauth.multitenant.connection.provider.MultiTenantConnectionProvider.getSessionFactory(MultiTenantConnectionProvider.java:80)
com.cherry.oauth.multitenant.dbhandler.TenantSesionFactory.getSession(TenantSesionFactory.java:49)
com.cherry.oauth.service.MyAuthServiceImpl.authenticate(MyAuthServiceImpl.java:89)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:483)
com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ObjectOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:258)
com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.catalina.filters.CorsFilter.handleSimpleCORS(CorsFilter.java:301)
org.apache.catalina.filters.CorsFilter.doFilter(CorsFilter.java:169)
函数代替rawQuery,因为它很容易处理。
在您的情况下,您的查询功能将是:
query