|
I can connect to the database in java, but it is not displayed in jsp? ? ?
Source program:
<% @ page contentType = "text / html; charset = GB2312"%>
<% @ page import = "java.sql. *"%>
<html>
<body> <FONT SIZE = 5>
<%
out.print ("<Table Border>");
out.print ("<TR>");
out.print ("<TH width = 100>" + "Student number");
out.print ("<TH width = 100>" + "Name");
out.print ("<TH width = 50>" + "math score");
out.print ("<TH width = 50>" + "English score");
out.print ("<TH width = 50>" + "Physical score");
out.print ("</ TR>");
try
{
Class.forName ("com.microsoft.jdbc.sqlserver.SQLServerDriver");
} catch (ClassNotFoundException e) {}
try
{
String url = "jdbc: microsoft: sqlserver: // localhost: 1433; DatabaseName = pubs";
String user = "myair99";
String password = "19831228";
Connection con = DriverManager.getConnection (url, user, password);
Statement st = con.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = st.executeQuery ("select * from students");
Ranch
while (rs.next ())
{
out.print ("<TD>" + rs.getString (1) + "</ TD>");
Ranch
}
rs.close ();
st.close ();
con.close ();
}
catch (Exception err) {
}
%>
</ body>
</ html>
After entering http: // localhost: 8080 / text.jsp
Can only display tables, but can't connect to the database? why?
It can be connected in java, and the contents of the students table have been displayed.
Thank you! !! !! ~ |
|