问题
I'm trying to establish a connection to an oracle database from an app written with play framework 2.0.4 and getting an SQLException (No suitable driver found for jdbc:oracle:thin:@....) when opening an connection.
I'm using code that works fine standealone and the connection string in the exception is ok too (even tested it in 'Execute Query' and it worked).
Play can even find my driver, because i have this statement at the beginning of my code which would throw a NoClassDefFound exception if the class was missing:
Class.forName("oracle.jdbc.driver.OracleDriver");
And the oracle driver in my lib directory is the same as i'm using in my sample app, ExecuteQuery, JBoss, etc.
What am i doing wrong?
Here another snippet from my code:
String connectionString = "jdbc:oracle:thin:@" + url + ":" + port + ":" + sid;
Connection conn = DriverManager.getConnection(connectionString, user, password);
PS: The db I want to access in this way is not my main database where i store my application data, but only a external read only datasource...
Thanks for any hints
Edit: The problem is solved now, but i have no clue how :\ I just ran my code in order to read the error message agan, but i'm not getting any error anymore. The only idea that i have is that last week when i didn't get it to work i did not restart the play console but only my app!?! Maybe this can be the reason?!
Edit2: Still happens from time to time without changing my set up but as soon as i restart my app it works again :)
回答1:
If the drivers are loaded then the url must be incorrect. Have you tried printing the connection string to check it is correct?
it should look like "jdbc:oracle:thin:@//localhost:1521/mydb"
来源:https://stackoverflow.com/questions/13763413/jdbc-connection-from-play-app