A typical example of jsp

Source: Internet
Author: User

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 ();
%>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.