Reputation: 267
So I was using JDBC with mySQL to connect to a test mySQL database in a java app and everything worked just fine. Production will end up being on an oracle database. It seems I can just change the Driver and Connection to make this work.
I was given this: /usr/local/oracle/product/10.1.0/client_1/bin/sqlplus -S user/password@SERVICE @something.sql
So I am assuming this is how it is accessed locally. I was given the host as well. So I thought the connection url would translate to the following and I'd be able to do this:
String url = "jdbc:oracle:thin:user/password@//host/SERVICE"
Connection c = DriverManager.getConnection(url);
but this does not seem to be working. I am confused by the @something.sql part. How would I include that in my connection url? Also are there any obvious errors in my current connection URL, "jdbc:oracle:thin:user/password@//host/SERVICE"?
Upvotes: 1
Views: 4081
Reputation: 10099
First, sqlplus is a command line utility from Oracle, and they gave you an example where values are supposed to be substituted in their example.
If you had a user named "ababa" who had a password "sesame". Suppose the service is "genie" on server "bottle". If the SQL one ran from a command line was "SELECT * FROM wishes LIMIT 3", which is in a file called "/tmp/wishes.sql".
From the command line, one might type the following:
/usr/local/oracle/product/10.1.0/client_1/bin/sqlplus -S ababa/sesame@genie @/tmp/wishes.sql
From Java, one would call:
Connection conn = DriverManager.getConnection("jdbc:oracle:thin://bottle/genie",
"ababa",
"sesame");
Upvotes: 2
Reputation: 3634
I don't normally use connection strings directly in my code anymore, but that looks mostly right. The real problem is that Oracle isn't standard, which is why you have the silly @ sign in there.
You might also find that some of your SQL won't work either. That's because Oracle has some quirks. You really should test your code against an oracle database before tossing it into production.
Upvotes: 0