It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Groovy connect to Oracle db Edited

I am trying to connect to oracle database with groovy . I have used the following code in groovy console 

import groovy.sql.*
import java.sql.Driver
try {
def driver = Class.forName('oracle.jdbc.driver.OracleDriver') as Driver
} catch (ClassNotFoundException e) {
println e.printStackTrace()
}
def url= "jdbc:oracle:thin:@192.168.100.78:1521:oraacc"
def username = "user"
def password = "password"
def sql = Sql.newInstance(url, username, password)
try {
sql.eachRow('select * from tableexample'){ row ->
println row
}
} finally {
sql.close()
}

but getting the following compilation error

java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@192.168.100.78:1521:oraacc

I have place ojdbc7.jar in the /home/jira/jira-server/lib folder and restarted Jira instance. I guess something wrong with classpath but can't found what wrong exactly.

Any ideas how to resolve this?

1 answer

1 accepted

0 votes
Answer accepted

Solved.

import groovy.sql.Sql
import java.sql.Driver

def driver = Class.forName('oracle.jdbc.OracleDriver').newInstance() as Driver
def props = new Properties()
props.setProperty("user", "user")
props.setProperty("password", "password")
def conn = driver.connect("jdbc:oracle:thin:@192.168.100.78:1521:oraacc", props)
def sql = new Sql(conn)
def results = sql.rows("select * from tableexample.repdata ")
return results

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Align

Best Practices in Jira Align

Hello Jira Align customers! In order to better serve you on your journey with Jira Align, the Community team has worked with the Jira Align team to curate the content in this collection to better s...

44 views 0 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you