将groovy应用程序连接到SQL Server Express

时间:2013-01-25 13:48:00

标签: grails jdbc datasource sql-server-express

我正在按照下面的教程进行操作,但必须有一些重要步骤才能假设我没有的知识。

http://padcom13.blogspot.co.uk/2011/01/setting-up-sql-server-2008-express-to.html

下面的

是我的datasource.groovy中的设置

username = "sa"
password = ""
url = "jdbc:sqlserver://localhost:1433;databaseName=Sandpit"
driverClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
dialect = "org.hibernate.dialect.SQLServerDialect"

及以下是运行应用程序命令

时弹出的错误
ERROR context.GrailsContextLoader  - Error executing bootstraps: 
Error creating bean with name 'transactionManagerPostProcessor': 
Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'transactionManager': 
Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'sessionFactory': 
Cannot resolve reference to bean 'lobHandlerDetector' while setting bean property 'lobHandler'; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'lobHandlerDetector': Invocation of init method failed; 
nested exception is org.springframework.jdbc.support.MetaDataAccessException: 
Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: 
Cannot load JDBC driver class 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
Message: Error creating bean with name 'transactionManagerPostProcessor': 
Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' 
while setting bean property 'sessionFactory'; nested exception is 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': 
Cannot resolve reference to bean 'lobHandlerDetector' while setting bean property 'lobHandler'; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'lobHandlerDetector': 
Invocation of init method failed; nested exception is 
org.springframework.jdbc.support.MetaDataAccessException: 
Error while extracting DatabaseMetaData; nested exception is 
org.apache.commons.dbcp.SQLNestedException: 
Cannot load JDBC driver class 'com.microsoft.sqlserver.jdbc.SQLServerDriver'

在没有看到我的应用程序运行的情况下工作了几天.....任何建议?

2 个答案:

答案 0 :(得分:4)

根本原因是Cannot load JDBC driver class 'com.microsoft.sqlserver.jdbc.SQLServerDriver'

那是因为你的驱动程序在类路径中丢失了。对于SQL Server,您需要将jar复制到lib文件夹。

在像MySQL这样的其他情况下,您可以声明为maven依赖。

答案 1 :(得分:0)

我们和你一样做着同样的事情。 因此,我们在/ lib -directory中有sqljdbc.jar。

在我们的DataSource.groovy中,我们有:

dbCreate = "update" // one of 'create', 'create-drop','update'
username = "dbo"
driverClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
url = "jdbc:sqlserver://devdb02:1433;databaseName=my_database;"

我记得只有.jar是不够的,我认为你需要在windows / unix目录中安装一小部分,例如从这里:

http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774

(如果您可以将PHP与MSSQL一起使用,也需要这样做)