jfinal连接sqlserver2008

@JFinal 波总,没办法,我快花了一周时间去配置jfinal连接sqlserver2008数据库了,然后我尝试用官网的demo来连接sqlserver,但是一直不行,求帮助。贴上我修改的地方。

数据库配置文件:blob.png

democonfig:

blob.png


导入的jar:

blob.png

然后是报错:


Starting JFinal 3.0

Starting scanner at interval of 5 seconds.

Starting web server on port: 80


2017-03-17 17:37:16

[ERROR]-[Thread: main]-[com.alibaba.druid.pool.DruidDataSource.init()]: dataSource init error

java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver

at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:510)

at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:563)

at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:876)

at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:872)

at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97)

at com.jfinal.plugin.activerecord.TableBuilder.build(TableBuilder.java:38)

at com.jfinal.plugin.activerecord.ActiveRecordPlugin.start(ActiveRecordPlugin.java:209)

at com.jfinal.core.Config.startPlugins(Config.java:107)

at com.jfinal.core.Config.configJFinal(Config.java:53)

at com.jfinal.core.JFinal.init(JFinal.java:63)

at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:49)

at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:119)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:724)

at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)

at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)

at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)

at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)

at org.eclipse.jetty.server.Server.doStart(Server.java:277)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at com.jfinal.server.JettyServer.doStart(JettyServer.java:131)

at com.jfinal.server.JettyServer.start(JettyServer.java:70)

at com.jfinal.core.JFinal.start(JFinal.java:159)

at com.demo.common.DemoConfig.main(DemoConfig.java:38)

Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:430)

at com.jfinal.server.JFinalClassLoader.loadClass(JFinalClassLoader.java:53)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Unknown Source)

at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:508)

... 25 more


2017-03-17 17:37:16

[ERROR]-[Thread: main]-[com.jfinal.core.Config.startPlugins()]: Plugin start error: com.jfinal.plugin.activerecord.ActiveRecordPlugin. 

java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver

com.jfinal.plugin.activerecord.ActiveRecordException: java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver

at com.jfinal.plugin.activerecord.TableBuilder.build(TableBuilder.java:50)

at com.jfinal.plugin.activerecord.ActiveRecordPlugin.start(ActiveRecordPlugin.java:209)

at com.jfinal.core.Config.startPlugins(Config.java:107)

at com.jfinal.core.Config.configJFinal(Config.java:53)

at com.jfinal.core.JFinal.init(JFinal.java:63)

at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:49)

at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:119)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:724)

at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)

at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)

at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)

at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)

at org.eclipse.jetty.server.Server.doStart(Server.java:277)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at com.jfinal.server.JettyServer.doStart(JettyServer.java:131)

at com.jfinal.server.JettyServer.start(JettyServer.java:70)

at com.jfinal.core.JFinal.start(JFinal.java:159)

at com.demo.common.DemoConfig.main(DemoConfig.java:38)

Caused by: java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver

at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:510)

at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:563)

at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:876)

at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:872)

at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97)

at com.jfinal.plugin.activerecord.TableBuilder.build(TableBuilder.java:38)

... 20 more

Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:430)

at com.jfinal.server.JFinalClassLoader.loadClass(JFinalClassLoader.java:53)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Unknown Source)

at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:508)

... 25 more

2017-03-17 17:37:16.603:WARN:oejuc.AbstractLifeCycle:FAILED jfinal: java.lang.RuntimeException: Plugin start error: com.jfinal.plugin.activerecord.ActiveRecordPlugin. |java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver

java.lang.RuntimeException: Plugin start error: com.jfinal.plugin.activerecord.ActiveRecordPlugin. |java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver

at com.jfinal.core.Config.startPlugins(Config.java:116)

at com.jfinal.core.Config.configJFinal(Config.java:53)

at com.jfinal.core.JFinal.init(JFinal.java:63)

at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:49)

at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:119)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:724)

at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)

at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)

at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)

at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)

at org.eclipse.jetty.server.Server.doStart(Server.java:277)

at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)

at com.jfinal.server.JettyServer.doStart(JettyServer.java:131)

at com.jfinal.server.JettyServer.start(JettyServer.java:70)

at com.jfinal.core.JFinal.start(JFinal.java:159)

at com.demo.common.DemoConfig.main(DemoConfig.java:38)

Caused by: 

如能解答,万分感激!

评论区

JFinal

2017-03-18 09:56

从异常上看是缺少相应的 jar 包,注意这里:Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver

liangjiang

2017-03-18 17:08

@JFinal 谢谢,的确是我的sqljdbc4.jar包有问题,里面没有com.microsoft.sqlserver.jdbc这个文件,重新下载一个就行了

威仔

2018-07-18 11:56

@JFinal 我连接sqlserver 数据库 表都是sqlserver的 但是提示:Starting JFinal 3.4
Starting scanner at interval of 5 seconds.
Starting web server on port: 80
Can not create Table object, maybe the table blog is not exists.

2018-07-18 11:43:07
[ERROR]-[Thread: main]-[com.jfinal.core.Config.startPlugins()]: Plugin start error: com.jfinal.plugin.activerecord.ActiveRecordPlugin.
com.microsoft.sqlserver.jdbc.SQLServerException: '`' 附近有语法错误。
com.jfinal.plugin.activerecord.ActiveRecordException: com.microsoft.sqlserver.jdbc.SQLServerException: '`' 附近有语法错误。
at com.jfinal.plugin.activerecord.TableBuilder.build(TableBuilder.java:55)
at com.jfinal.plugin.activerecord.ActiveRecordPlugin.start(ActiveRecordPlugin.java:226)
at com.jfinal.core.Config.startPlugins(Config.java:128)
at com.jfinal.core.Config.configPluginWithOrder(Config.java:71)

威仔

2018-07-18 11:57

用的官网demo

威仔

2018-07-18 12:01

arp.setDialect(new AnsiSqlDialect()); 加上这句就好了,解决了@JFinal

JFinal

2018-07-18 15:58

@威仔 你用的 sqlserver , 应该要配置它的方言:
arp.setDialect(new SqlServerDialect())

不要使用 AnsiSqlDialect,这个是为 jfinal 里面默认没有方言的数据库准备的

威仔

2018-07-18 16:25

@JFinal public static DataSource getDataSource() {
PropKit.use("database.properties");
DruidPlugin druidPlugin = BaseConfig.createDruidPlugin();
druidPlugin.start();
return druidPlugin.getDataSource();
}


但是自动生成 哪里 是没法设置 arp.setDialect(new SqlServerDialect()) 还是报什么的错无,启动是没有问题了

威仔

2018-07-18 16:25

自动生成是只只支持 mysql吗?

JFinal

2018-07-18 17:15

@威仔 生成器一样也可以配置方言:
generator.setDialect(new SqlServerDialect());

下载首页的 jfinal demo,里面的生成器就有这个配置

威仔

2018-07-18 18:30

@JFinal 已经看到了 谢谢

热门反馈

扫码入社