Classic example of JSP

zhaozj2021-02-11  226

Linux-JSP-JDBC-MySQL Test - SELECT

Keywords: Java, JSP

<% - Author: Raymond [hhzqq@21cn.com] Date: 2000-08-04 features: Linux-JSP-JDBC-MySQL test - Select -%> <% @ page contentType = "text / html; charset = 8859_1 "%> <% // declaration java.sql.connection sqlconn; // database connection object java.sql.statement SQLSTMT; // statement object java.sql.resultset Sqlrst; // Results Object // Register JDBC driver Class.Forname ("org.gjt.mm.mysql.driver"). NewInstance (); // Connect database SQLCONN = java.sql.driverManager.getConnection ("JDBC: MySQL: // localhost / test", "test" , "test"); // create a statement object sqlStmt = sqlConn.createStatement (java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY); // execute SQL statements sqlRst = sqlStmt.executeQuery ( "select name, age From test ");%> Name Age <% while (sqlrst.next ()) {%> <% = sqlrst.getstring (1)%> <% = SQLRST.GETLONG ( 2)%> <%}%> <% // Close Result Set Object Sqlrst.close (); // Off Statement Object SQLSTMT.Close (); // Close the database connection SQLConn.close ();%>

转载请注明原文地址:https://www.9cbs.com/read-4472.html

New Post(0)