主题:各位高手摆脱了。一个与数据库连接时的程序
请各位高手给指导一下,我在上课的时候有这样一个程序
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<html>
<body>
<% Connection con;
Statement sql;
ResultSet rs;
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e) {out.print("asd"); }
try{ con=DriverManager.getConnection("jdbc: odbc: sun","administrator","");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM student");
out.print("<table border>");
out.print("<tr>");
out.print("<th width=100>"+"学号"+"</th>");
out.print("<th width=100>"+"姓名"+"</th>");
out.print("<th width=100>"+"数学成绩"+"</th>");
out.print("<th width=100>"+"英语成绩"+"</th>");
out.print("<th width=100>"+"物理成绩"+"</th>");
out.print("</tr>");
while(rs.next())
{ out.print("<tr>");
out.print("<td >"+rs.getString(1)+"</td>");
out.print("<td >"+rs.getString(2)+"</td>");
out.print("<td >"+rs.getFloat("数学成绩")+"</td>");
out.print("<td >"+rs.getFloat("英语成绩")+"</td>");
out.print("<td >"+rs.getFloat("物理成绩")+"</td>");
out.print("</tr>");
}
out.print("</table>");
con.close();
}
catch(SQLException el){out.print("cvb"); }
%>
</body>
</html>
运行以后就在屏幕上显示cvb,我不知道这个异常怎么解决。谢谢各位了
数据库和数据源应该都没有问题。
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<html>
<body>
<% Connection con;
Statement sql;
ResultSet rs;
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e) {out.print("asd"); }
try{ con=DriverManager.getConnection("jdbc: odbc: sun","administrator","");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM student");
out.print("<table border>");
out.print("<tr>");
out.print("<th width=100>"+"学号"+"</th>");
out.print("<th width=100>"+"姓名"+"</th>");
out.print("<th width=100>"+"数学成绩"+"</th>");
out.print("<th width=100>"+"英语成绩"+"</th>");
out.print("<th width=100>"+"物理成绩"+"</th>");
out.print("</tr>");
while(rs.next())
{ out.print("<tr>");
out.print("<td >"+rs.getString(1)+"</td>");
out.print("<td >"+rs.getString(2)+"</td>");
out.print("<td >"+rs.getFloat("数学成绩")+"</td>");
out.print("<td >"+rs.getFloat("英语成绩")+"</td>");
out.print("<td >"+rs.getFloat("物理成绩")+"</td>");
out.print("</tr>");
}
out.print("</table>");
con.close();
}
catch(SQLException el){out.print("cvb"); }
%>
</body>
</html>
运行以后就在屏幕上显示cvb,我不知道这个异常怎么解决。谢谢各位了
数据库和数据源应该都没有问题。