大神求帮忙
<%@ page contentType="text/html;charset=GB2312" %><%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>添加新数据后的数据显示</title>
</head>
<body>
<div align="center">插入后的数据库为:</div>
<%
String in_xuehao=request.getParameter("insert_xuehao");
if(in_xuehao==null) {in_xuehao=""; }
byte b[]=in_xuehao.getBytes("ISO-8859-1");
in_xuehao=new String(b);
String in_name=request.getParameter("insert_name");
if(in_name==null) {in_name=""; }
String in_易做图=request.getParameter("insert_易做图");
if(in_易做图==null) {in_易做图=""; }
String in_age=request.getParameter("insert_age");
if(in_age==null) {in_age=""; }
String in_jiguan=request.getParameter("insert_jiguan");
if(in_jiguan==null) {in_jiguan=""; }
String in_dept=request.getParameter("insert_dept");
if(in_dept==null) {in_dept=""; }
Connection con=null;
Statement sql=null;
ResultSet rs=null;
String xuehao,name,易做图,jiguan,dept;
int age;
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){out.print("mmm"+e);}
try {con=DriverManager.getConnection("jdbc:odbc:university","" ,"");
sql=con.createStatement();
String condition1=
"Insert INTO student(Xuehao,Name,Sex,Age,Jiguan,Dept) VALUES("+"'"+in_xuehao+"','"+in_name+"',"+in_易做图+",'"+in_age+"','"+in_jiguan+"','"+in_dept+"'"+")" ;
//执行更新操作:
sql.executeUpdate(condition1);
Connection con;
Statement sql;
ResultSet rs;
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){out.print("abb"+e+"bb");}
try{ con=DriverManager.getConnection("jdbc:odbc:university","","");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM student");
out.print("<Table Border=1 align=center>");
out.print("<TR>");
out.print("<TH width=100>"+"学号");
out.print("<TH width=100>"+"姓名");
out.print("<TH width=50>"+"性别");
out.print("<TH width=50>"+"年龄");
out.print("<TH width=50>"+"籍贯");
out.print("<TH width=50>"+"部门");
out.print("<TH width=50>"+"更改");
out.print("<TH width=50>"+"删除");
out.print("</TR>");
while(rs.next())
{ out.print("<TR>");
xuehao=rs.getString("Xuehao");
out.print("<TD >"+xuehao+"</TD>");
name=rs.getString("Name");
out.print("<TD >"+name+"</TD>");
易做图=rs.getString("Sex");
out.print("<TD >"+易做图+"</TD>");
age=rs.getInt("Age");
out.print("<TD >"+age+"</TD>");
jiguan=rs.getString("Jiguan");
out.print("<TD >"+jiguan+"</TD>");
dept=rs.getString("Dept");
out.print("<TD >"+dept+"</TD>");
out.print("<TD >"+"<a href=Change.jsp>"+"修改"+"</a>"+"</TD>");
out.print("<TD >"+"<a href=Del.jsp>"+"删除"+"</a>"+"</TD>");
out.print("</TR>");
}
out.print("</Table>");
out.print("<div align=center>"+"<a href=Insert.jsp>"+"添加新的记录"+"</a>"+"</div>");
con.close();
}
catch(SQLException e) {out.print("aaaa"+e+"aaaa"); }
finally{
}
%>
</body>
</html>
出错地方:<%
出错原因:insert "finally" to complete TryStatement --------------------编程问答-------------------- 有一个try没有catch或者finally与之配对 --------------------编程问答-------------------- 很明显
语法错误 --------------------编程问答-------------------- 你少了一个catch
仔细看下。你一有个嵌套的try块没有catch.
try {con=DriverManager.getConnection("jdbc:odbc:university","" ,"");
sql=con.createStatement();
String condition1=
"Insert INTO student(Xuehao,Name,Sex,Age,Jiguan,Dept) VALUES("+"'"+in_xuehao+"','"+in_name+"',"+in_易做图+",'"+in_age+"','"+in_jiguan+"','"+in_dept+"'"+")" ;
//执行更新操作:
sql.executeUpdate(condition1);
Connection con;
Statement sql;
ResultSet rs;
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){out.print("abb"+e+"bb");}
--------------------编程问答-------------------- 这个。。。我们没学过java和jsp。。。但是这学期开了这门课,这是我根据老师的代码所改写出来的。。。 --------------------编程问答-------------------- 易做图 明显 少了个大括号 并且
Connection con=null;
Statement sql=null;
ResultSet rs=null;
这三个变量 申明了两次
<%@ page contentType="text/html;charset=GB2312"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">
<title>添加新数据后的数据显示</title>
</head>
<body>
<div align="center">
插入后的数据库为:
</div>
<%
String in_xuehao=request.getParameter("insert_xuehao");
if(in_xuehao==null) {
in_xuehao="";
}
byte b[]=in_xuehao.getBytes("ISO-8859-1");
in_xuehao=new String(b);
String in_name=request.getParameter("insert_name");
if(in_name==null) {
in_name="";
}
String in_易做图=request.getParameter("insert_易做图");
if(in_易做图==null) {
in_易做图="";
}
String in_age=request.getParameter("insert_age");
if(in_age==null) {
in_age="";
}
String in_jiguan=request.getParameter("insert_jiguan");
if(in_jiguan==null) {
in_jiguan="";
}
String in_dept=request.getParameter("insert_dept");
if(in_dept==null) {
in_dept="";
}
Connection con=null;
Statement sql=null;
ResultSet rs=null;
String xuehao,name,易做图,jiguan,dept;
int age;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException e){
out.print("mmm"+e);
}
try {
con=DriverManager.getConnection("jdbc:odbc:university","" ,"");
sql=con.createStatement();
String condition1=
"Insert INTO student(Xuehao,Name,Sex,Age,Jiguan,Dept) VALUES("+"'"+in_xuehao+"','"+in_name+"',"+in_易做图+",'"+in_age+"','"+in_jiguan+"','"+in_dept+"'"+")" ;
//执行更新操作:
sql.executeUpdate(condition1);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(
ClassNotFoundException e){out.print("abb"+e+"bb");
}
try{
con=DriverManager.getConnection("jdbc:odbc:university","","");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM student");
out.print("<Table Border=1 align=center>");
out.print("<TR>");
out.print("<TH width=100>"+"学号");
out.print("<TH width=100>"+"姓名");
out.print("<TH width=50>"+"性别");
out.print("<TH width=50>"+"年龄");
out.print("<TH width=50>"+"籍贯");
out.print("<TH width=50>"+"部门");
out.print("<TH width=50>"+"更改");
out.print("<TH width=50>"+"删除");
out.print("</TR>");
while(rs.next())
{ out.print("<TR>");
xuehao=rs.getString("Xuehao");
out.print("<TD >"+xuehao+"</TD>");
name=rs.getString("Name");
out.print("<TD >"+name+"</TD>");
易做图=rs.getString("Sex");
out.print("<TD >"+易做图+"</TD>");
age=rs.getInt("Age");
out.print("<TD >"+age+"</TD>");
jiguan=rs.getString("Jiguan");
out.print("<TD >"+jiguan+"</TD>");
dept=rs.getString("Dept");
out.print("<TD >"+dept+"</TD>");
out.print("<TD >"+"<a href=Change.jsp>"+"修改"+"</a>"+"</TD>");
out.print("<TD >"+"<a href=Del.jsp>"+"删除"+"</a>"+"</TD>");
out.print("</TR>");
}
out.print("</Table>");
out.print("<div align=center>"+"<a href=Insert.jsp>"+"添加新的记录"+"</a>"+"</div>");
con.close();
}catch(SQLException e) {
out.print("aaaa"+e+"aaaa");
}
}catch(Exception e){
}finally{
}
%>
</body>
</html>
--------------------编程问答-------------------- JSP嵌入java代码,主要就是要认真仔细啦~~~ --------------------编程问答-------------------- 完全看不明白
补充:Java , Web 开发