Linux-jsp (preferred for SUN Enterprise Applications)-JDBC-MySQL (best combination with PHP) Test-Select
Keywords:Java and jsp (preferred for SUN Enterprise applications)
<% --
Author: He Zhiqiang [hhzqq@21cn.com]
Date: 2000-08-04
Function: Linux-jsp (preferred for SUN Enterprise Applications)-JDBC-MySQL (best combination with PHP) Test-Select
-- %>
<% @ Page contentType = "text/html; charset = 8859_1" %>
<%
// Statement
Java. SQL. Connection sqlConn; // database Connection object
Java. SQL. Statement sqlStmt; // Statement object
Java. SQL. ResultSet sqlRst; // result set object
// Register the JDBC driver
Class. forName ("org. gjt. mm. MySQL (the best combination with PHP). Driver"). newInstance ();
// Connect to the database
SqlConn = java. SQL. DriverManager. getConnection ("jdbc: MySQL (the best combination with PHP): // localhost/test", "test", "test ");
// Create a statement object
SqlStmt = sqlConn. createStatement (java. SQL. ResultSet. TYPE_SCROLL_INSENSITIVE, java. SQL. ResultSet. CONCUR_READ_ONLY );
// Execute the SQL statement
SqlRst = sqlStmt.exe cuteQuery ("select name, age from test ");
%>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> Linux-jsp (preferred for SUN Enterprise Applications)-JDBC-MySQL (best combination with PHP) Test-Select </title>
</Head>
<Body>
<Table border = "1" cellspacing = "0" cellpadding = "0" align = "center">
<Tr>
<Th> name </th>
<Th> age </th>
</Tr>
<% While (sqlRst. next () {%>
<Tr>
<Td> <% = sqlRst. getString (1) %> </td>
<Td> <% = sqlRst. getLong (2) %> </td>
</Tr>
<% }%>
</Table>
</Body>
</Html>
<%
// Close the result set object
SqlRst. close ();
// Close the statement object
SqlStmt. close ();
// Close the database connection
SqlConn. close ();
%>