如何进行动态表数据查询?

假设有连接池: 

DruidPlugin druidPlugin = DruidPlugin(.get().get().get().trim())me.add(druidPlugin)
ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);


我现在需要由客户端请求一个sql记录集,这个记录集会涉及多表关联,显示字段由sql语句指定, 返回记录集需要能够读取到字段类型、字段名、字段值,数据是通过json返回给客户端,并非直接展现在浏览器中。

请问我该如何实现? 有类似示例吗? 谢谢!

评论区

lhl_yn_km

2019-07-30 09:28

DruidPlugin druidPlugin = new DruidPlugin(p.get("jdbcUrl"), p.get("user"), p.get("password").trim());
try {
druidPlugin.start(); //此行报错
ActiveRecordPlugin arp = new ActiveRecordPlugin("MysqlConnect", druidPlugin);
arp.start();


List resultRecordList = new ArrayList<>();
resultRecordList = Db.use("MysqlConnect").find("SELECT * FROM blog");

for (Record ItemRc : resultRecordList) {
System.out.println(ItemRc.get("title").toString());
}
}
catch (Exception e)
{
e.printStackTrace();
System.out.println (e.getMessage());
}

问题1, druidPlugin.start(); 报错:
2019-07-30 09:21:23.022:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.w.WebAppContext@6379eb{/,file:///E:/work/DataCore/DbCore/web/,UNAVAILABLE}
java.lang.NoClassDefFoundError: com/alibaba/druid/pool/DruidDataSource
at com.jfinal.plugin.druid.DruidPlugin.start(DruidPlugin.java:180)
at com.config.MainConfig.configPlugin(MainConfig.java:94)
at com.jfinal.core.Config.configPluginWithOrder(Config.java:70)
at com.jfinal.core.Config.configJFinal(Config.java:59)
at com.jfinal.core.JFinal.init(JFinal.java:61)
at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:63)
at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:139)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:741)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:374)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:847)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:287)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
at org.eclipse.jetty.server.Server.start(Server.java:416)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:108)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.server.Server.doStart(Server.java:383)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at com.jfinal.server.jetty.JettyServer.doStart(JettyServer.java:154)
at com.jfinal.server.jetty.JettyServer.start(JettyServer.java:70)
at com.jfinal.core.JFinal.start(JFinal.java:160)
at com.jfinal.core.JFinal.start(JFinal.java:182)
at com.config.MainConfig.main(MainConfig.java:25)

lhl_yn_km

2019-07-30 09:35

报错位置:
protected void doStart() throws Exception {
try {
this._metadata.setAllowDuplicateFragmentNames(this.isAllowDuplicateFragmentNames());
Boolean validate = (Boolean)this.getAttribute("org.eclipse.jetty.webapp.validateXml");
this._metadata.setValidateXml(validate != null && validate);
this.preConfigure();
super.doStart();
this.postConfigure();
if (this.isLogUrlOnStart()) {
this.dumpUrl();
}
} catch (Throwable var2) {
LOG.warn("Failed startup of context " + this, var2); // 这里打出的异常信息
this._unavailableException = var2;
this.setAvailable(false);
if (this.isThrowUnavailableOnStartupException()) {
throw var2;
}
}


java.lang.NoClassDefFoundError: com/alibaba/druid/pool/DruidDataSource
at com.jfinal.plugin.druid.DruidPlugin.start(DruidPlugin.java:180)
at com.config.MainConfig.configPlugin(MainConfig.java:94)
at com.jfinal.core.Config.configPluginWithOrder(Config.java:70)
at com.jfinal.core.Config.configJFinal(Config.java:59)
at com.jfinal.core.JFinal.init(JFinal.java:61)
at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:63)
at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:139)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:741)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:374)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:847)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:287)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
at org.eclipse.jetty.server.Server.start(Server.java:416)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:108)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.server.Server.doStart(Server.java:383)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at com.jfinal.server.jetty.JettyServer.doStart(JettyServer.java:154)
at com.jfinal.server.jetty.JettyServer.start(JettyServer.java:70)
at com.jfinal.core.JFinal.start(JFinal.java:160)
at com.jfinal.core.JFinal.start(JFinal.java:182)
at com.config.MainConfig.main(MainConfig.java:25)
Caused by:
java.lang.ClassNotFoundException: com.alibaba.druid.pool.DruidDataSource
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:565)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at com.jfinal.plugin.druid.DruidPlugin.start(DruidPlugin.java:180)
at com.config.MainConfig.configPlugin(MainConfig.java:94)
at com.jfinal.core.Config.configPluginWithOrder(Config.java:70)
at com.jfinal.core.Config.configJFinal(Config.java:59)
at com.jfinal.core.JFinal.init(JFinal.java:61)
at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:63)
at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:139)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:741)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:374)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:847)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:287)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138)
at org.eclipse.jetty.server.Server.start(Server.java:416)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:108)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.server.Server.doStart(Server.java:383)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at com.jfinal.server.jetty.JettyServer.doStart(JettyServer.java:154)
at com.jfinal.server.jetty.JettyServer.start(JettyServer.java:70)
at com.jfinal.core.JFinal.start(JFinal.java:160)
at com.jfinal.core.JFinal.start(JFinal.java:182)
at com.config.MainConfig.main(MainConfig.java:25)

lhl_yn_km

2019-07-30 10:05

搞定了,忘记加 mql库了 ,谢谢支持

热门反馈

扫码入社