连接方法:
1.将Oracle的JDBC驱动程序(oracle/jbdc/lib/classes12.jar),拷贝到Tomcat安装目录的lib文件夹下;
2.驱动程序:oracle.jdbc.driver.OracleDriver
3.连接地址:jdbc:oracle:thin:@localhost:1521:数据库名
实例:
jdbc_mysql.jsp:
01.<%@ page contentType="text/html;charset=GB2312" %>
02.
<%@ page import="java.sql.*" %>
03.
<
html
>
04.
<
head
>
05.
<
title
>jdbc_mysql</
title
>
06.
</
head
>
07.
08.
<
body
>
09.
<%!
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
>