1, with database software (such as: MySQL) to create a database, the database registered with the database name is just the data created
Library, if it is a data source name, ODBC configuration is required.
2, the driver will be placed in the D:\Tomcat 5.5\common\lib or the corresponding development tools of the LIB,
For D:\Tomcat 5.5\conf\web.xml modifications, open Web.xml, add the following in front of </web-app>:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/mysql</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Navigate through the folder to D:\Tomcat 5.5\conf\catalina\localhost, and find your Web application corresponding to the. XML text
Pieces, such as Root.xml, and add code to the bottom of this file:
<resourcelink name= "Jdbc/mysql" global= "Jdbc/mysql"
Type= "Javax.sql.DataSourcer"/>
Here, the configuration work is basically done.
3, the database connection (note: The following is reproduced)
First, JSP connection oracle8/8i/9i database (with thin mode)
Testoracle.jsp is as follows:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<body>
<%Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl";
//orcl为你的数据库的SID
String user="scott";
String password="tiger";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement
(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功,恭喜你\");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>