显示错误 - 找不到合适的驱动程序jdbc:oracle:thin:@localhost:1521:orcl
问题描述:
我正在使用jdk1.8,我试图在oracle 8i上手动执行jdbc程序。我的代码编译没有任何错误,但在运行时显示错误 - no suitable driver found for jdbc:oracle:thin:@localhost:1521:orcl
。我已经设置了jar文件的类路径。我正在使用ojdbc7.jar
文件。 我的代码是:显示错误 - 找不到合适的驱动程序jdbc:oracle:thin:@localhost:1521:orcl
import java.sql.*;
class Database
{
public static void main(String arg[])
{
try
{
String url="jdbc:orcl:thin:@localhost:1521:orcl";
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(url,"scott","tiger");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from aj1");
while(rs.next())
{
System.out.println("\n"+rs.getInt(1)+" "+rs.getString(2));
}
}
catch(Exception e){e.printStackTrace();}
}
}
请给出这方面的解决方案:
答
您的URL字符串必须
字符串URL =“的jdbc:神谕:薄:@localhost: 1521:ORCL“;
代替
字符串URL = “JDBC:ORCL:瘦:@localhost:1521:ORCL”;
并尝试。