1.需要下载class12.jar
下载地址:http://down.51cto.com/data/2124426
2.解压放到tomcat安装目录下的lib文件夹下
3.在webapps/ROOT/下创建1.jsp输入下面代码
代码如下 :
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.sql.Statement"%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="d3ecc5">
<p> </p>
<%
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn= DriverManager.getConnection("jdbc:oracle:thin:@10.0.78.35:1521:prod1","junly","huang");
\\服务器地址,实例名称,账号,密码
Statement stat1=conn.createStatement();
ResultSet rs = stat1.executeQuery("select * from HAHAHAHA");
\\事先创建好的表
while(rs.next())
{
out.println(rs.getString(1));
}
out.println("Connection OK...");
rs.close();
stat1.close();
conn.close();
}
catch(Exception e) {
out.println("Failed ...");
out.println(e.toString());
}
%>
</div>
</body>
</html>