我已经使用JDK1.6安装了NetBeans 6.5。我想在NetBeans 6.5中使用java与oracle进行连接。问题是:JDBC精简连接
如何将JDBC配置为java 1.6?
感谢, Sopolin
我已经使用JDK1.6安装了NetBeans 6.5。我想在NetBeans 6.5中使用java与oracle进行连接。问题是:JDBC精简连接
如何将JDBC配置为java 1.6?
感谢, Sopolin
这里的提示:1.下载 从以下站点正确的Oracle数据库驱动程序版本: http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html 并导入到NetBeans的libary如果你使用NetBeans IDE作为。
2.In你的Java代码,定义一样,适当的JDBC连接声明:
public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
public static final String DBURL = "jdbc:oracle:thin:@localhost:1521:Your_DB_NAME";
public static final String DBUSER = "YOUR ORACLE DB ID" ;
public static final String DBPASS = "YOUR ORACLE DB PASSWORD" ;
Connection conn = null ; // DB CONNECTIONS
PreparedStatement pstmt = null ;// DB OPERATIONS
ResultSet rs = null ; // save the query result
Class.forName(DBDRIVER) ; // Load the ORACLE DRIVER
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS) ;
String sql = "SELECT name FROM client" ; //sample query
pstmt = conn.prepareStatement(sql) ; // execute the query and save the result
// the above cope snippet is the main things of JDBC.
//Hope it helps!
您好,我看到了你的参考,但我效仿的榜样在这个网站之后,我有错误发生。在线程“main”中的异常java.lang.NoClassDefFoundError:C:\ TestJava \ DbTest 原因:java.lang.ClassNotFoundException:c:\ TestJava \ DbTest at java.net.URLClassLoader $ 1.run(Unknown Source).. ... 你能指导我在oracle中使用java配置JDBC Thin驱动程序吗? – Sopolin 2009-08-22 04:21:47
你如何执行你的程序看起来像你做错了什么。它应该看起来像java -cp ... DbTest你在使用什么IDE,因为通过IDE运行和配置应用程序更容易。 – pjp 2009-08-22 16:18:53
是的,我复制了DbTest以运行测试。然后当我跑它时,它出现这个错误。 – Sopolin 2009-08-24 01:40:18