I am setting up a Grails 2.3.5 App on a Heroku Server and I keep getting the following error when tomcat starts up:
Caused by: java.sql.SQLException: Driver:com.mysql.jdbc.Driver#5a7359fe returned null for URL:jdbc:h2:mem:grailsDB;MVCC=TRUE;LOCK_TIMEOUT=10000
I am not using h2 as the Database. I would like to use ClearDB. My environment variables all look correct and everything looks correct in DataSource.groovy. I even setup the connection string to be hard coded to see if this would make a difference. Nada.
production {
datasource {
dbCreate = "create-drop"
url = "jdbc:mysql://us-cdbr-east-05.cleardb.net/heroku_5a952ab6aXXXXXXX?reconnect=true"
username = "XXXXX"
password = "xxxxx"
}
}
Obviously I'm missing something, but I cannot see what.
Where is the production setup getting the h2 connection string from?!
You don't show your full DataSource.groovy file, but it probably has the H2 driver in the top section (driverClassName = "org.h2.Driver"). The values there are the defaults, and the environment-specific blocks are merged into that to create the final settings. You can override that in the production block
production {
datasource {
dbCreate = "create-drop"
url = "jdbc:mysql://us-cdbr-east-05.cleardb.net/heroku_5a952ab6aXXXXXXX?reconnect=true"
username = "XXXXX"
password = "xxxxx"
driverClassName = 'com.mysql.jdbc.Driver'
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
}
}
Additionally, you should always specify the dialect when using MySQL. Grails auto-detects the dialect well in most cases, but can't determine if you're using MyISAM or InnoDB, so it defaults to a dialect that uses the default engine type configured for the whole server. Newer versions of MySQL default to InnoDB and it's easy to change it in any version, but if you don't or it's an older version you'll end up with non-transactional MyISAM tables. Specifying the dialect ensures that your app uses the proper table type.
I found out the reason for my problems.
The code block for data source has a lower case "s" in source. It should have been dataSource, not datasource.
When this block is missing, it appears the default is a h2 database with the name "grailsDB". I could not find this documented anywhere, hence all my confusion.
Check your cases!!!!
Related
I'm developing an application for multi tenant purpose, for this, I've used Orchestral/Tenanti but I'm experiencing the following problem.
I already performed some of the required steps for Multi Database Connection Setup.
Configuration Tenant Driver for Multiple Database: on my tenanti.php
Setting Default Database Connection: on my Tenant.php Middleware
Definition of my Tenants Connection: on my config/database.php
The problem becomes on the Database Connection Resolver step. In my Middleware I'm defining the connection to be used (I don't post the code because is not relevant for Tenanti use) which is correctly setted.
My resolver code is:
public function boot()
{
Tenanti::connection('tenants', function (User $entity, array $template) {
$template['database'] = "db_{$entity->getKey()}";
return $template;
});
}
This code is located on my AppServiceProvider. But my database to be used, is not correctly setted from my Resolver, throwing the following error:
ErrorException in MySqlConnector.php line 110:
Undefined variable: database
Clearly the error means that database is no setted.
Someone can help? Thanks in advance.
After many tests, I didn't find the solution using Tenanti, instead of that, I used Config class to set the database to use, and maintained my tenants configuration on database.php.
Config::set('database.connections.tenants.database', 'legal_'.$request->route()->parameter('account'));
Config::set('database.default', 'tenants');
I am trying to override dataSource.url value running grails from the command line, example
grails <set property> dbm-status
My first try was using -D command line parameter as
grails -DdataSource.url=jdbc:sqlserver://xx.xx.xx.xx;databaseName=db_name
I have tried to add an additional config file to grails.config.locations that get values from System.getProperty but does not seems to work.
Exist a built in way to override config values from the command line, otherwise how I can inject parameter from the command line to the grails configuration ?
EDIT: I don't want to use another environment/datasource to avoid datasource configuration duplication and the need to configure things for this new environment.
By including the following if in DataSource.groovy I'm able to override url,password and username property if url is provided. (Valid for Grails 2.x)
....
environments {
development {
dataSource {
url = "jdbc:postgresql://localhost/db"
username = "user"
password = "pass"
if (System.properties['dataSourceUrl']) {
println 'Taking dataSource url, password, username from command line overrides'
url = System.properties['dataSourceUrl']
password = System.properties['dataSourcePassword']
username = System.properties['dataSourceUsername']
}
}
}
...
Now when I run the command, the overrides get applied:
grails dev -DdataSourceUrl=newUrl -DdataSourcePassword=newPass -DdataSourceUsername=newUser run-app
Unfortunately if you want to be able to override on every environment you have to duplicate this code for every env block. If you pull it up to root it won't work since config merging kicks in and the last run will actually apply what's in the env {} block and not what's in the System properties.
Looking at it again something like that looks even better:
...
url = System.properties['dataSourceUrl'] ?: 'jdbc:postgresql://localhost/db'
//and for every property...
...
DATASOURCE_URL=jdbc:sqlserver://xx.xx.xx.xx;databaseName=db_name grials run-app
For any variable you want to set, you can set it in the environment. Change to upper case and replace dots with underscores. This is a feature of spring boot.
I'm importing a exists grails project, this project use postgresql use remote postgresql, they built it on real machine, now I need do it on my localhost machine, and use postgresql local.
Everything is OK, but the system can use postgresql, althought I set up it in datasource.config. My datasource.config is similar to old real one, just change something between remote server and local server. Here is my datasource.config.
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
production {
pooled = true
driverClassName = "org.postgresql.Driver"
username = "postgres"
password = "postgres"
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate'
url = "jdbc:postgresql://localhost:5432/faql_dev"
}
}
Here is some error I got:
Caused by: org.compass.gps.device.hibernate.HibernateGpsDeviceException: {hibernate}: Failed to index the database; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query using scroll
at org.compass.gps.device.hibernate.indexer.ScrollableHibernateIndexEntitiesIndexer.performIndex(ScrollableHibernateIndexEntitiesIndexer.java:172)
at org.compass.gps.device.support.parallel.ConcurrentParallelIndexExecutor$1$1.doInCompassWithoutResult(ConcurrentParallelIndexExecutor.java:104)
at org.compass.core.CompassCallbackWithoutResult.doInCompass(CompassCallbackWithoutResult.java:29)
at org.compass.core.CompassTemplate.execute(CompassTemplate.java:133)
at org.compass.gps.impl.SingleCompassGps.executeForIndex(SingleCompassGps.java:147)
at org.compass.gps.device.support.parallel.ConcurrentParallelIndexExecutor$1.call(ConcurrentParallelIndexExecutor.java:102)
... 5 more
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query using scroll
at org.compass.gps.device.hibernate.indexer.ScrollableHibernateIndexEntitiesIndexer.performIndex(ScrollableHibernateIndexEntitiesIndexer.java:118)
... 10 more
Caused by: org.h2.jdbc.JdbcSQLException: Table "QUESTION" not found; SQL statement:
I imported everything involve to postgresql, So I can create table based on domain in development mode, but I can't run it. In production, it will throw that exception.
Thanks in advance!
Caused by: org.h2.jdbc.JdbcSQLException
This suggests to me that you're using the wrong JDBC driver. The data source configuration you've posted only sets the app up to use Postgres in production mode, if you run locally in dev mode then it'll use the default H2 database.
I'm trying to get a Grails web-app going on jetty-7.6.3 on an IBM AS400. When I do, I get an error that boils down to:
Caused by:
java.sql.SQLException: INTERNAL ERROR: Creation of DB2Driver object for registering with DriverManager failed. -> com.ibm.db2.jdbc.app.DB2JDBCDataException: CCSID value is not valid.
at com.ibm.db2.jdbc.app.DB2ErrorDriver.throwSavedExceptions(DB2ErrorDriver.java:113)
at com.ibm.db2.jdbc.app.DB2ErrorDriver.handleURLProcessing(DB2ErrorDriver.java:296)
at com.ibm.db2.jdbc.app.DB2ErrorDriver.acceptsURL(DB2ErrorDriver.java:149)
at java.sql.DriverManager.getDriver(DriverManager.java:386)
at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy$TransactionAwareInvocationHandler.invoke(TransactionAwareDataSourceProxy.java:224)
at $Proxy16.getMetaData(Unknown Source)
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:285)
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:320)
at org.codehaus.groovy.grails.orm.hibernate.support.SpringLobHandlerDetectorFactoryBean.afterPropertiesSet(SpringLobHandlerDetectorFactoryBean.java:72)
...
I can provide more of the stacktrace if that would be helpful.
Here is my datasource:
dataSource{
dbCreate = "update"
pooled = true
url = "jdbc:db2:*local;naming=system;libraries=LIBV;errors=full"
driverClassName = "com.ibm.db2.jdbc.app.DB2Driver"
username = "user"
password = "pass"
dialect = org.hibernate.dialect.DB2400Dialect.class
}
I have no idea where to start on this or which file has the wrong CCSID. I've looked through all the files for my web-app and they seem to be fine. Any suggestions?
I'm not a Grails programmer but I'm familiar with IBM i. IBM Support document 29290926 says that CCSID 65535 is not allowed.
Quite a few midrange machines were sold and set up decades ago, when there was no CCSID. As the operating system evolved, the notion of CCSID - Coded Character Set ID - was introduced. When that happened, people upgrading to the new version of the OS were assigned a default CCSID: 65535. CCSID 65535 in effect says 'I have no idea how your files are encoded'. In effect, all the files are treated as though they are binary data like a JPG or an EXE file.
The recommendation back then was to not allow the default, but to assign a CCSID that described the actual encoding. Where I am in the US, that CCSID is 37 - US English. There is a system value called QCCSID which will set this system-wide. Another approach is to change the user profile involved. CHGUSRPRF username CCSID(37)
I am reading Grails in Action and it says to use
dataSource {
dbCreate = "update"
url = "jdbc:hsqldb:file:devDB;shutdown=true"
}
This causes an error when I run grails console: Unsupported connection setting "SHUTDOWN"
grails console works fine when I remove ;shutdown=true
What is shutdown=true meant to do?
This is described here: http://www.hsqldb.org/doc/guide/ch04.html
It's probably not useful for an in-memory database since it is lost when the web server stops anyway.