JSP连接sql2000所遇到的问题
在程序中我设置好了数据源头,JSP程序也写好了,但是在TOMCAT中运行的时候就是没有结果程序如下:
<%@ page contentType="text/html; charset=gb2312"%>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<%
Connection con;
Statement sql;
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(
ClassNotFoundException e){}
try{
con=DriverManager.getConnection("jdbc.odbc:student","sa","");
sql=con.createStatement();
rs=sql.executeQuery("select *from chengji");
out.print("<Table border>");
out.print("<tr>");
out.print("<th width=100>"+"学号");
out.print("<th width=100>"+"姓名");
out.print("<th width=100>"+"数学");
out.print("<th width=100>"+"英语");
out.print("<tr>");
while(rs.next()){
out.print("<tr>");
out.print("<td>"+rs.getString(1)+"</td>");
out.print("<td>"+rs.getString(1)+"</td>");
out.print("<td>"+rs.getInt("数学")+"</td>");
out.print("<td>"+rs.getInt("英语")+"</td>");
out.print("</tr>");
}
out.print("</table>");
con.close();
}
catch(
SQLException e1){}
%>
</body>
</html>
------解决方案--------------------
最好还是 使用连接字符串
扑捉了错误,还是把错误信息打印出来吧,才知道是什么原因!!
实例:
http://www.javawind.net/5b016f381a924efb011a96bd26600004.jhtml