Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,554,452
Community Members
 
Community Events
184
Community Groups

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
AUG Leaders

Atlassian Community Events