Reputation: 11
import java.sql.*;
public class Jdbcdemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection c=DriverManager.getConnection("jdbc.oracle:thin:@hp-hp:1521:xe","system", "ashu41228");
if(c!=null)
{
System.out.println("DataBase is Created");
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
java.sql.SQLException: No suitable driver found for jdbc.oracle:thin:@hp-hp:1521:xe at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at Jdbcdemo.main(Jdbcdemo.java:12)
the above exception is coming i dont know how to tackle this.pls help
Upvotes: 0
Views: 2380
Reputation: 96454
The error message you're getting does not necessarily mean you don't have the right driver or that you don't have a driver in your classpath. I think you must have a driver in your classpath because the Class.forName
call succeeded. According to the FAQ you should be loading "oracle.jdbc.OracleDriver", but you're finding something and that's a good sign.
Your JDBC url should start with jdbc:oracle:thin:
(not jdbc.oracle:thin:
). Even if everything else is right, getting the prefix wrong will cause the "No suitable driver found" error to occur (I verified this with the Oracle jars in my classpath and a JDBC url that I know works):
groovy:000> url = "jdbc.oracle:thin:@//localhost:1521/FOOBAR"
groovy:000> DriverManager.getConnection(url, "asdf", "zxcv")
ERROR java.sql.SQLException: No suitable driver found for jdbc.oracle:thin:@//localhost:1521/FOOBAR
at java_sql_DriverManager$getConnection.call (Unknown Source)
at groovysh_evaluate.run (groovysh_evaluate:4)
...
Once you get the prefix right then if the rest of the url has a problem you will get a different error:
groovy:000> url = "jdbc:oracle:thin:@//localhost:1521/FOOBAR"
groovy:000> DriverManager.getConnection(url, "asdf", "asdf")
ERROR java.sql.SQLRecoverableException:
IO Error: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon (T4CConnection.java:419)
at oracle.jdbc.driver.PhysicalConnection.<init> (PhysicalConnection.java
:536)
at oracle.jdbc.driver.T4CConnection.<init> (T4CConnection.java:228)
at oracle.jdbc.driver.T4CDriverExtension.getConnection (T4CDriverExtensi
on.java:32)
at oracle.jdbc.driver.OracleDriver.connect (OracleDriver.java:521)
at java_sql_DriverManager$getConnection.call (Unknown Source)
at groovysh_evaluate.run (groovysh_evaluate:4)
...
Usually the url is something like
jdbc:oracle:thin:@//dbserver:port/databasename
Check with your DBA to find out what the right url should be.
Upvotes: 1
Reputation: 21101
According to the stacktrace,
java.sql.SQLException: No suitable driver found
It looks like you don't have suitable driver for Oracle database. To solve this problem, you'll have to have Oracle JDBC driver in your classpath.
You can download suitable driver from oracle site and add the package to your build path.
Refer to this article to set your classpath or other SO questions.
Upvotes: 1