无法从Groovy连接到Oracle数据库

无法从Groovy连接到Oracle数据库

问题描述:

我无法在groovy中连接到oracle数据库.我已经在groovy控制台中使用了以下代码,但是得到了以下编译错误

Hi i am unable to connect to oracle database in groovy . I have used the following code in groovy console but getting the following compilation error

unable to resolve class oracle.jdbc.driver.OracleTypes
 at line: 5, column: 1

我使用了以下代码

import java.sql.Connection
import java.sql.DriverManager
import javax.sql.DataSource
import groovy.sql.Sql
import oracle.jdbc.driver.OracleTypes

sql = Sql.newInstance("jdbc:oracle:thin:@localhost:1521:databasename",
               "username", "password", "oracle.jdbc.OracleDriver")

如果我删除import oracle.jdbc.driver.OracleTypes语句,我将得到以下WARNING: Sanitizing stacktrace:.请帮助我解决该问题,请将ojdbc14.jar放在lib文件夹中.

If i remove import oracle.jdbc.driver.OracleTypes statement i am getting the following WARNING: Sanitizing stacktrace:.Kindly help me how to resolve this i have place ojdbc14.jar in the lib folder.

newInstance 调用中删除所有不必要的导入和驱动程序类,如下所示:

Remove all unnecessary imports and driver class from newInstance call as follows:

import groovy.sql.Sql

sql = Sql.newInstance("jdbc:oracle:thin:@localhost:1521:databasename", "username", "password")

上面的内容就足够了,对我来说很好用,但是我使用的是ojdbc6-11.2.jar

The above is enough and works just fine for me, however I'm using ojdbc6-11.2.jar

此外,取决于您使用的是 SID 还是服务名称,可能必须将JDBC URL的最后一个分号更改为斜杠.

Beside depends on if you are using SID or service name the last semicolon at JDBC URL might have to be changed for slash.