I am trying to test a grails app connecting to a sql server, for now, I am using one of my own. This is my datasource.groovy
dataSource {
configClass = GrailsAnnotationConfiguration.class
pooled = true
driverClassName = "oracle.jdbc.driver.OracleDriver"
dialect = "org.hibernate.dialect.Oracle10gDialect"
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:oracle:thin:#127.0.0.1:1521/xe"
username = "blah"
password = "blah"
properties {
validationQuery="select 1 from dual"
testWhileIdle=true
timeBetweenEvictionRunsMillis=60000
}
}
I have borrowed this code from a different app, just changing the url and user/password. The other app runs fine, but my app throws a long exception, which boils down to this
Caused by SQLNestedException: Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver'
stack trace
Caused by ClassNotFoundException: oracle.jdbc.driver.OracleDriver
I have copied ojdbc6.jar into my app lib/ but I am afraid I am lost on what to do next.
EDIT I have updated oracle.jdbc.driver.OracleDriver to oracle.jdbc.OracleDriver, but no progress
Run
grails compile --refresh-dependencies
when you add a jar to the lib directory so Grails adds it to the classpath. This is a new requirement in 2.0+
Unrelated - you can remove
configClass = GrailsAnnotationConfiguration.class
since that's the default now
Shouldn't the class be:
driverClassName = "oracle.jdbc.OracleDriver"
I believe the other one was deprecated
So, turns out the problem was what #tim_yates suggested. The problem that I had since then was that even though I was refreshing the dependencies, as #burt said, but I had never re-loaded the config files.
I just ran grails clean then grails compile --refresh-dependencies and voila, problem solved. Thanks to #burt and #tim_yates for helping me out
Related
Trying to get the combo jython-zxJDBC-UCanAccess working on my Windows machine; been driving me nuts the entire day as I keep getting
zxJDBC.DatabaseError ( driver [net.ucanaccess.jdbc.UcanaccessDriver] not found ), and
zxJDBC.DatabaseError ( driver [ucanaccess] not found )
I had been using this sample code from Gord Thompson with my particulars - keeps failing with driver-not-found errors whatever I try:
from com.ziclix.python.sql import zxJDBC
#Or also import ucanaccess
jdbc_url = "jdbc:ucanaccess://Z:/Companies.accdb"
username = ""
password = ""
driver_class = "net.ucanaccess.jdbc.UcanaccessDriver"
#Or driver_class = "net.ucanaccess.jdbc.UcanloadDriver"
cnxn = zxJDBC.connect(jdbc_url, username, password, driver_class)
crsr = cnxn.cursor()
crsr.execute("SELECT * FROM tblSICs")
for row in crsr.fetchall():
print row[0]
crsr.close()
cnxn.close()
Jython alone works well, I use it with the SikuliX IDE
'from ... import zxJDBC' passes without error
UCanAccess works fine from the command line (console.bat) with my MS
Access database; all 5 JARs are in and as in the CLASSPATH variable
What I don't get is what is "driver_class"?. I thought that the database-specific driver gets located by means of Jython/SikuliX looking in CLASSPATH, where the '.../ucanaccess-5.0.0.jar' is seen.
Here the CLASSPATH:
"c:\Users\User\AppData\Roaming\UCanAccess\lib\hsqldb-2.5.0.jar;c:\Users\User\AppData\Roaming\UCanAccess\lib\jackcess-3.0.1.jar;c:\Users\User\AppData\Roaming\UCanAccess\lib\commons-lang3-3.8.1.jar;c:\Users\User\AppData\Roaming\UCanAccess\lib\commons-logging
-1.2.jar;c:\Users\User\AppData\Roaming\UCanAccess\ucanaccess-5.0.0.jar"
And here is where the SikuliX IDE looks for resources:
D:\Drawer 3\Sikuli\Training\UCanAccess.sikuli Z:\test.sikuli
C:\Users\User\AppData\Roaming\Sikulix\Lib\site-packages
C:\Users\User\AppData\Roaming\Sikulix\Lib
C:\Users\User\AppData\Roaming\Sikulix\Extensions\Lib
C:\Users\User\AppData\Roaming\Sikulix\Extensions\jython-standalone-2.7.2.jar\Lib
classpath
pyclasspath/
Does anyone spot the issue?
Issue was found to be a special twist of SikuliX 2.0.4 which cannot evaluate the CLASSPATH variable. Here the workarounds / SiluliX' way to get to know the location of JARs:
Two Solutions:
Solution A
SikuliX IDE looks into the folder
<C:\Users\User\AppData\Roaming\Sikulix\Extensions>; all five relevant
JAR files need to be places in that folder (no 'lib' subfolder as in
the deployment pack):
ucanaccess-5.0.0.jar
commons-lang3-3.8.1.jar
commons-logging-1.2.jar
hsqldb-2.5.0.jar
jackcess-3.0.1.jar
Check the extension JARs that get found by seeing
SikuliX->Tools->Extensions...
Solution B
Leave the needed JARs in their original deployment folder, and add
their path to the 'Special File'
'C:\Users\User\AppData\Roaming\Sikulix\Extensions\extensions.txt' as:
ucanaccess = C:/Users/User/AppData/Roaming/UCanAccess/ucanaccess-5.0.0.jar
C:/Users/User/AppData/Roaming/UCanAccess/lib/commons-lang3-3.8.1.jar
C:/Users/User/AppData/Roaming/UCanAccess/lib/commons-logging-1.2.jar
C:/Users/User/AppData/Roaming/UCanAccess/lib/hsqldb-2.5.0.jar
C:/Users/User/AppData/Roaming/UCanAccess/lib/jackcess-3.0.1.jar
This will be evaluated, as a workaround, instead of the CLASSPATH
variable
Thanks for your help!
I'm trying to create a Spring Boot application using sqljdbc4 driver with this config:
spring:
datasource:
url: "jdbc:sqlserver://dbhost:1433;databaseName=test"
username: dbuser
password: dbuser
tomcat:
test-on-borrow: true
validation-query: select 1
But, when I run, I get this error: Unable to detect database type
I was debugging BatchDatabaseInitializer, where error came from, and when it calls JdbcUtils.commonDatabaseName(...), "Microsoft SQL Server" is returned as product name that doesn't match with any DatabaseDriver's product name.
I tried other drivers but they all have the same problem.
Is it a bug?
I'm using Spring Boot 1.5.1-RELEASE.
You need to properly configure your spring.datasource config in application.properties file if you're using spring-batch to create batch jobs. Below is mine ->
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/batch_repo
spring.datasource.username=batch_username
spring.datasource.password=batch_password
spring.datasource.platform=mysql
spring.batch.initialize-schema=always
spring.batch.initialize-schema when configured to "always", will create the necessary spring batch related tables in your schema.
Alternatively, if you assign it to "never", it will refrain from creating the tables. In both these cases your error should get resolved.
Try spring.batch.jdbc.initialize-schema=never in props file. It worked for me in spring-boot v2.6.x
Add this in your Application file within the main function.
#SpringBootApplication(
exclude = {
BatchAutoConfiguration.class,
JmxAutoConfiguration.class
},
excludeName = {
"org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration",
}
)
Put this in your application.properties.
spring.batch.schema=classpath:org/springframework/batch/core/schema-sqlserver.sql
Check your application.properties file like below.
Note: springbatch is my DB name
spring.datasource.url=jdbc:mysql://localhost:3306/springbatch
spring.datasource.username=root
spring.datasource.password=Vishal#123
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.batch.jdbc.initialize-schema=always
I'm building a Play! Framework (2.5) Java application and I want to connect it to ElasticSearch using Ebean.
First, I followed the steps here and successfully connected to a dummy jdbc (Added plugin, modified build.sbt, added ebean.default="models.*", default.driver = org.h2.Driver, and default.url = "jdbc:h2:mem:play" to application.conf). So far so good.
Now, I want to switch my connection to ElasticSearch instead of jdbc, so I'm following the steps here, but I can't figure it out for the life of me. What I've done so far:
Added to build.sbt:
libraryDependencies ++= Seq( "org.avaje.ebeanorm" % "avaje-ebeanorm-elastic" % "1.3.1" )
Added to application.conf:
ebean.docstore.url="http://localhost:9200"
ebean.docstore.active=true
ebean.docstore.generateMapping=true
ebean.docstore.dropCreate=true`
Removed from application.conf
default.driver = org.h2.Driver
default.url = "jdbc:h2:mem:play"
I cannot get this code to run, because I keep getting this error:
RuntimeException: com.typesafe.config.ConfigException$WrongType: application.conf # file:/C:/Users/../conf/application.conf: 357-360: docstore has type OBJECT rather than LIST
I would greatly appreciate any pointers in the right direction. Thanks!
You can either :
Override your ebean configuration programmaticaly
Add your configuration in a ebean property file
1 - Programmatically
package models;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.event.ServerConfigStartup;
public class ConfigOverride implements ServerConfigStartup {
public void onStart(ServerConfig serverConfig) {
serverConfig.getDocStoreConfig().setUrl("http://localhost:9200");
serverConfig.getDocStoreConfig().setActive(true);
serverConfig.getDocStoreConfig().setGenerateMapping(false);
serverConfig.getDocStoreConfig().setDropCreate(false);
serverConfig.getDocStoreConfig().setCreate(false);
serverConfig.getDocStoreConfig().setPathToResources("conf");
}
}
2 - Configuration
You have to put your ebean.docstore properties in a ebean.properties in conf directory. But unfortunatly, I didn't manage to make the application work in stage mode
Source: https://raw.githubusercontent.com/playframework/play-ebean/master/docs/manual/working/javaGuide/main/sql/JavaEbean.md
FYI : I opened an issue here :
https://github.com/playframework/play-ebean/issues/104
Updated Question based upon feedback:
I have a spring-boot application that has three databases: H2 for integration testing, and Postgresql for qa & production. Since spring-boot creates a default datasource for you, I don't have anything defined for my integration tests. I thought I would use application.properties to define my datasource connection values but I am not certain what is the best way to handle this.
I have two files:
src/main/resources/application.properties
spring.profiles.active=production
appName = myProduct
serverPort=9001
spring.datasource.url=jdbc:postgresql://localhost/myDatabase
spring.datasource.username=user
spring.datasource.password=password
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.hibernate.hbm2ddl.auto=update
spring.jpa.hibernate.ejb.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.hibernate.show_sql=true
spring.jpa.hibernate.format_sql=true
spring.jpa.hibernate.use_sql_comments=false
spring.jpa.hibernate.type=all
spring.jpa.hibernate.disableConnectionTracking=true
spring.jpa.hibernate.default_schema=dental
src/main/resources/application-test.properties
spring.profiles.active=test
serverPort=9002
spring.datasource.url = jdbc:h2:~/testdb
spring.datasource.username = sa
spring.datasource.password =
spring.datasource.driverClassName = org.h2.Driver
liquibase.changeLog=classpath:/db/changelog/db.changelog-master.sql
I used to run my tests with with gradle (using "gradle build test") or within IntelliJ. I updated my gradle file to use:
task setTestEnv {
run { systemProperty "spring.profiles.active", "test" }
}
But when I run gradle clean build setTestEnv test I get errors that seem to indicate the test is trying to connect to an actual Postgresql database:
Caused by: org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:138)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22)
at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:32)
at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:393)
at org.postgresql.Driver.connect(Driver.java:267)
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:278)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:701)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:635)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:486)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:144)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:127)
at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:288)
... 42 more
Caused by: java.net.ConnectException: Connection refused
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
I haven't figured out how to set the default system.property == "test" within IntelliJ yet...
See section 21.3 of the Spring Boot documentation. This section describes how to define profile specific property files that use the format application-{profile}.properties. This can help you isolate properties on a per profile basis.
You can annotate your tests adding #ActiveProfiles in the following way:
#SpringApplicationConfiguration(classes = {Application.class, TestSpringConfiguration.class})
#Test(groups = "integration")
#ActiveProfiles("test")
public class MyServiceTest extends AbstractTransactionalTestNGSpringContextTests {
...
#Test
public void testSomething() {
...
}
}
I'm using TestNG but JUnint wouldn't be much different.
You can also specify additional configuration as showed in the example above.
That way you won't need to set the profile in build.gradle or launch configuration in IntelliJ
I am trying to write a program to connect to HBase. However when I execute following command
HBaseConfiguration.create(); I get following error: .
"hbase-default.xml file seems to be for and old version of HBase (null), this version is 0.92.1-cdh4.1.2.
When I dig deep and debug inside observe following:
class HBaseConfiguration
private static void checkDefaultsVersion(Configuration conf) {
if (conf.getBoolean("hbase.defaults.for.version.skip", Boolean.FALSE))return;
String defaultsVersion = conf.get("hbase.defaults.for.version");
String thisVersion = VersionInfo.getVersion();
if (!thisVersion.equals(defaultsVersion)) {
throw new RuntimeException(
"hbase-default.xml file seems to be for and old version of HBase (" +
defaultsVersion + "), this version is " + thisVersion);
}
}
In my case HBase returns default version as null, I am not sure why its returning as null as I checked the corresponding entry in hbase-default.xml packaged with the HBase.jar it has correct entry.
When I try the same thing from a standalone program it works as expected.
Guyz, Please let me know if you have any questions.
Thanks in advance,
Rohit
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property>
<name>hbase.defaults.for.version.skip</name>
<value>true</value>
</property>
</configuration>
Add this to a hbase-default.xml and put the file in the classpath or resource foldr. I got it when i ran from within spring hadoop environment. By adding above file to reosurce folder of the job jar i was able to solve tis-
finally found the workaround to this problem...
The problem is hbase-default.xml is not included in your classpath.
I added hbase-default.xml in target/test-classes ( it will vary in your case ), you can just add hbase-default.xml in various folder and see what works for you.
NOTE : This is just workaround, not the solution
Solution will be load the proper jars ( which I haven't figured out yet )
I've been getting this error using HBase1.1.1.
I created a simple HBase client and it worked fine. Then I built a simple RMI service, and that worked fine. But when I tried putting my simple HBase query code into RMI service I started getting this error on the HBaseConfiguration.create() call. After playing a bit, I found that the HBaseConfiguration.create() call works OK if placed before the security manager stuff that is in my main(). I get the error if the call is placed after block of code containing security manager calls...
Configuration conf = HBaseConfiguration.create(); // This works
if(System.getSecurityManager() == null)
{
System.setSecurityManager(new SecurityManager());
} // End if
// Configuration conf = HBaseConfiguration.create(); // This fails
I get the error if the create() call happens in main() after that security manager block, or in code within the class that is instantiated by main(). I don't get the error if create() is called within a static{ } block in my RMI service class (which I believe gets called before main()), or in main() before the security manager block, as shown.
BTW, the jar files that I include in my class path in order to get a minimal client to run are the following:
commons-codec-1.9.jar,
commons-collections-3.2.1.jar,
commons-configuration-1.6.jar,
commons-lang-2.6.jar,
commons-logging-1.2.jar,
guava-12.0.1.jar,
hadoop-auth-2.5.1.jar,
hadoop-common-2.5.1.jar,
hbase-client-1.1.1.jar,
hbase-common-1.1.1.jar,
hbase-hadoop2-compat-1.1.1.jar,
hbase-it-1.1.1-tests.jar,
hbase-protocol-1.1.1.jar,
htrace-core-3.1.0-incubating.jar,
log4j-1.2.17.jar,
netty-all-4.0.23.Final.jar,
protobuf-java-2.5.0.jar,
slf4j-api-1.7.7.jar,
slf4j-log4j12-1.7.5.jar
Had a similar problem where the error was
java.lang.RuntimeException: hbase-default.xml file seems to be for and old version of HBase (0.98.3-hadoop2), this version is Unknown
at org.apache.hadoop.hbase.HBaseConfiguration.checkDefaultsVersion(HBaseConfiguration.java:70)
at org.apache.hadoop.hbase.HBaseConfiguration.addHbaseResources(HBaseConfiguration.java:102)
at org.apache.hadoop.hbase.HBaseConfiguration.create(HBaseConfiguration.java:113)
In my case I had same set of jar files at two different levels of classpath, removed from one level and it worked fine.
In my case the issue was caused by old java version (1.5), which was default on the server. But it works fine with 1.7.
In my code, I used this to solve my error.
val config = HBaseConfiguration.create() //error
val config = new Configuration() //works