JDBC 2 Concurrent Connections

I am able to use JDBC to connect to an Oracle DB or a MySQL DB. It works great. Now I am trying to connect to both databases at the same time. How do I do that? Can I use two different drivers at the same time?

Here’s an example of the MySQL connection. How would I also add a connection to Oracle in the same script?

using JDBC

JDBC.usedriver(MYSQL_DRIVER)
JDBC.init()
mysqlConn = JDBC.Connection("jdbc:mysql://$MYSQL_SERVER:$MYSQL_PORT/$MYSQL_SCHEMA?user=$MYSQL_USER&password=$MYSQL_PASS&useSSL=false")
mysqlCursor = cursor(mysqlConn)

strSQL = "select * from manu_history limit 5 "
println(strSQL)
execute!(mysqlCursor, strSQL)

column_names = map(x -> Symbol(x), JDBC.colnames(JDBC.Source(mysqlCursor)))
println(column_names)

for r in rows(mysqlCursor)
    println(r)
end

close(mysqlCursor)
close(mysqlConn)

JDBC.destroy()

To use multiple drivers, just need to set the classpath before calling init. So something like:

using JDBC
JDBC.usedriver("path_to_oracle_driver")
JDBC.usedriver("path_to_mysql_driver")
JDBC.init()

conn1 = DriverManager.getConnection(<oracle connection string>)
conn2 =  DriverManager.getConnection (<mysql connection string>)
.....
<use conn and conn2 to make queries and fetch data>
......
close(conn1)
close(conn2)
1 Like