JSP中连接Oracle数据库

JSP中连接Oracle数据库
连接方法:
1.将Oracle的JDBC驱动程序(oracle\jbdc\lib\classes12.jar),拷贝到Tomcat安装目录的lib文件夹下;
2.驱动程序:oracle.jdbc.driver.OracleDriver
3.连接地址:jdbc:oracle:thin:@localhost:1521:数据库名

实例:
jdbc_mysql.jsp:
view plaincopy to clipboardprint?
1. <%@ page contentType="text/html;charset=GB2312" %> 
2. <%@ page import="java.sql.*" %> 
3. <html> 
4.   <head> 
5.     <title>jdbc_mysql</title> 
6.   </head> 
7.     
8.   <body> 
9. <%!  
10.     String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;  
11.     String DBURL = "jdbc:oracle:thin:@localhost:1521:mgc" ;  
12.     String DBUSER = "system" ;  
13.     String DBPASSWORD = "admin" ;  
14.     Connection conn = null ;  
15.     Statement stmt = null ;  
16.     String sql = null ;  
17. %> 
18. <%  
19.     try {  
20.       
21.         Class.forName(DBDRIVER) ;  
22.         conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;  
23.         stmt = conn.createStatement();  
24.         sql = "Insert INTO member (id,username,password) VALUES(10,'qwe','qwe')" ;  
25.         stmt.executeUpdate(sql) ;  
26.         stmt.close() ;  
27.         conn.close() ;  
28.     }  
29.     catch(Exception e) {  
30.       
31.         System.out.println(e) ;  
32.     }  
33. %> 
34.   </body> 
35. </html> 


你可能感兴趣的:(oracle,sql,mysql,jsp,jdbc)