1. Test Sybase jconnect-5_2 JDBC Database interface with one JSP file:
<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "java.sql.*"%>
< Html>
<TITLE> jsp test Sybase jconnect-5_2 JDBC Database interface </title>
<meta name= " Generator "content=" "EditPlus2.11"
<meta name= "Author" content= "naxin"
<body
<center>jsp test Sybase jconnect-5_2 JDBC Database interface </center>
<br><br>
<table Border=3 align=center
<%
Class.forName ("Com.sybase.jdbc2.jdbc.SybDriver");
String url = "jdbc:sybase:tds:localhost:2638";
Connection conn= drivermanager.getconnection (URL, "DBA", "SQL");
Statement stmt=conn.createstatement ();
String sql= "Select Emp_lname,dept_id,street,city,state from Employee order by Emp_lname";
ResultSet rs=stmt.executequery (SQL);
while (Rs.next ()) {
Out.print ("<TR><TD>" +rs.getstring ("emp_lname") + "</TD>");
Out.print ("<TD>" +rs.getstring ("dept_id") + ";/td> ");
Out.print ("<TD>" +rs.getstring ("street") + "</TD>");
Out.print ("<TD>" +rs.getstring ("City") + "</TD>");
Out.print ("<TD>" +rs.getstring ("state") + "</TD></TR>");
}
%>
</table>
<br> <%out.print ("Successful database operation, congratulations");%>
<%
Rs.close ();
Stmt.close ();
Conn.close ();
%>
</body>
2. Reuse the JSP and Java Bean methods:
JSP Code:
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<HTML>
<HEAD>
<TITLE> </TITLE>
<META NAME="Generator" CONTENT="EditPlus2.11">
<META NAME="Author" CONTENT="naxin">
</HEAD>
<BODY>
<jsp:useBean id="sybase" scope="page" class="test.sybconn" />
<%
ResultSet rs=sybase.Query("select * from tjck_dh");
while(rs.next()) {
out.print("|"+rs.getString("name")+"|");
out.print(rs.getString("card_no")+"|");
out.print(rs.getString("amount")+"|");
out.print(rs.getString("home_call")+"|");
out.print(rs.getString("office_call")+"|<br>");
}
rs.close();
%>
<HR>