I. Environment Configuration
First, add the driver to classpath.
1. storage location of the driver when connecting to MySQL:
Driver name: mysql-connector-java-3.1.5-gamma-bin.jar
Path: tomcat5.5/common/lib
It takes effect after you restart tomcat.
2. storage location of the driver when connecting to Oracle:
Driver name: classes12.jar
Path: tomcat5.5/common/lib
It takes effect after you restart tomcat.
Ii. TestCode
<% @ page contenttype = "text/html; charset = gb2312" %>
<% @ page import = "Java. SQL. * "%>
<%
class. forname ("org. gjt. mm. mySQL. driver "). newinstance ();
string url = "JDBC: mysql: // localhost/db_name? User = yourusername & Password = yourpassword & useunicode = true & characterencoding = gb2312 ";
connection conn = drivermanager. getconnection (URL);
statement stmt = Conn. createstatement ();
string query = "select field_name from table_name order by ID";
resultset rs1_stmt.exe cutequery (query);
while (RS. next ()
{< br> string S = Rs. getstring ("field_name"); // check whether your field is of the struct type. Otherwise, you cannot use getstring. Use getboolean Based on the field class.
out. print (S + "
");
}< BR >%>