gpt4 book ai didi

java - java程序中的oracle数据库连接

转载 作者:行者123 更新时间:2023-12-02 12:22:21 25 4
gpt4 key购买 nike

enter image description here

 import java.sql.*;
import java.io.*;

public class OracleCon {


public static void main(String []args)throws ClassNotFoundException,SQLException,IOException
{

Class.forName("oracle.jdbc.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin@localhost:1521:xe", "system", "123456789");
Statement st=con.createStatement();
String sql="insert into citylist values ('vijay','54222','110001')";
int r=st.executeUpdate(sql);

if(r>0)
{
System.out.print("value inserted");
}
else
{
System.out.print("value not inserted");
}
//ResultSet rs=st.executeQuery(sql);

//while(rs.next())
// System.out.println(rs.getString(1)+""+rs.getString(2)+""+rs.getString(3));
con.close();


}
}

我在windows 7上安装了oracle 11g和jdk 1.8

Exception in thread "main" java.lang.ClassNotFoundException:oracle.jdbc.driver.OracleDriver at java.net.URLClassLoader.findClass(Unknown source) at java.lang.ClassLoader.loadClass (Unknown source)

最佳答案

当您在命令行中运行程序时,必须在类路径参数前面包含 jar 文件路径,如下所示:

java OracleCon -classpath c:\somepath\ojdbc6.jar

关于java - java程序中的oracle数据库连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45673008/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com