我已经使用JDK1.6安装了NetBeans 6.5。我想在NetBeans 6.5中将oracle与java连接起来。问题是:
如何将JDBC配置为java 1.6?
谢谢, Sopolin
答案 0 :(得分:4)
答案 1 :(得分:1)
答案 2 :(得分:1)
以下是提示: 1.从以下站点下载适当的ORACLE DB驱动程序版本: http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html 如果您使用NETBEANS作为IDE,则导入到Netbeans的库中。
2.在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!