我在sql developer中创建了一个小表,我需要以随机顺序从该数据库中检索信息,然后重写,但是我是开发新手,我花了很多时间打开连接但是无法获得它我一直在java.sql.SQLException: No suitable driver
。
代码
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class nameApp {
public static void main(String[] args) {
Connection connection;
try {
connection = DriverManager.getConnection("jdbc:oracle:thin:@10.244.227.86:1522:CMARRP1T", "User1","User1");
connection.close();
} catch (SQLException e) {
System.err.println(e);
}
}
}
答案 0 :(得分:0)
在分配连接之前进行此操作
Class.forName("oracle.jdbc.driver.OracleDriver");
答案 1 :(得分:0)
试试这个:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class nameApp {
public static void main(String[] args) {
Connection connection;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection("jdbc:oracle:thin:@10.244.227.86:1522:CMARRP1T", "User1","User1");
connection.close();
} catch (SQLException e) {
System.err.println(e);
}
}
}
另外,请确保您的类路径中存在Ojdbc驱动程序。那会让你工作。