回 帖 发 新 帖 刷新版面

主题:大家来帮帮忙啊!!

[em10]这是我程序的代码,运行后提示:sql error!

大家帮忙解决一下啊!

还有就是关键字:"Statement"为什么不变色?而"Connection"和"ResultSet"这两个关键字都能变色啊?!是不是这里出问题了?!

请大家帮忙!!谢谢了!

<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>学籍管理系统</title>
</head>

<body>
<% Connection con;
Statement sql;
ResultSet rs;
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){out.print("java.error");}
try { con=DriverManager.getConnection("jdbc:odbc:sun","lujia","1");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM students");

out.print("<table width=600 border>");
out.print("<TR>");
out.print("<TH width=100 align=center>"+"学号");
out.print("<TH width=100 align=center>"+"姓名");
out.print("<TH width=50 align=center>"+"性别");
out.print("<TH width=50 align=center>"+"年龄");
out.print("<TH width=100 align=center>"+"籍贯");
out.print("<TH width=100 align=center>"+"院系");
out.print("<TH width=50 align=center>"+"更改");
out.print("<TH width=50 align=center>"+"删除");
out.print("</TR>");
while(rs.next())
{out.print("<tr>");
out.print("<td width=100 align=center>"+rs.getString(1)+"</td>");
out.print("<td width=100 align=center>"+rs.getString(2)+"</td>");
out.print("<td width=50 align=center>"+rs.getString(3)+"</td>");
out.print("<td width=50 align=center>"+rs.getString(4)+"</td>");
out.print("<td width=100 align=center>"+rs.getString(5)+"</td>");
out.print("<td width=100 align=center>"+rs.getString(6)+"</td>");
out.print("<td width=50 align=center>"+rs.getString(1)+"</td>");
out.print("<td width=50 align=center>"+rs.getString(1)+"</td>");
out.print("</tr>");
}
out.print("</table>");
con.close();
}
catch(SQLException e1) {out.print("sql error!");}
%>
</body>
</html>

回复列表 (共2个回复)

沙发

out.print("<td width=50 align=center>"+rs.getString(1)+"</td>");
out.print("<td width=50 align=center>"+rs.getString(1)+"</td>");
该两行语句错误.

板凳

老大!这里应该怎么改呀?!

我来回复

您尚未登录,请登录后再回复。点此登录或注册