高手!请进啊!给分啊100
我用的是TOMCAT,怎么写一个类,连接数据库,然后调用啊,我在页面中写了连接数据库的代码,但是不能在每个页面中都写这段代码啊,所以我想请教一下高手啊,怎么写啊?在线等,我的代码是这样子的,<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@10.67.12.203:1521:DYGB";
//orcl为你的数据库的SID
String user="lz";
String password="123";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select NTABLE,NFIELD from XXZBDYB1";
ResultSet rs=stmt.executeQuery(sql);
%>
<table border="1">
<%while(rs.next()) {%>
<tr>
<td width="15%">
<%=rs.getString(1)%>
</td>
<td width="15%">
<%=rs.getString(2)%>
</td>
</tr>
<%}%>
</table>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>