myjava 2006-5-25 22:12
求助,总是出现“try”without“catch”
[quote]
import java.sql.*;
public class teacher {
String id;
String name;
String password;
String title;
public void setPassword(String s){password = s;}
public String getPassword(){return password;}
public void setName(String s){name=s;}
public String getName(){return name;}
public void setTitle(String s){title=s;}
public String getTitle(){return title;}
public void setId(String id){this.id=id;}
public String getId(){return id;}
public ResultSet getCourse( ){
String sql="select course.name "+
"from classes,course "+
"where classes.tea_id='"+id+"' "+
"and course.id=classes.cour_id";
sqlBean sqlbean = new sqlBean();
ResultSet rs = sqlbean.executeQuery(sql);
return rs;
}
public boolean hasLogin(String id){ //检查该教师是否已经注册
boolean f=true;
String sql="select id from teacher where id ='"+id+"'";
sqlBean db =new sqlBean();
try{
ResultSet rs=db.executeQuery(sql);
if(rs.next()){ f=false;}
else{ f=true;}
}catch(Exception e){ e.getMessage();}
return f;}
public void addTeacher(){
String sql="insert into teacher(id,name,title,password) "+
"values('"+id+"','"+name+"','"+title+"','"+password+"') ";
sqlBean db =new sqlBean();
db.executeInsert(sql);
}
public ResultSet getAll(){
String sql="select * from teacher";
sqlBean db =new sqlBean();
ResultSet rs = db.executeQuery(sql);
return rs;
}
public void update() {
String sql= "update teacher "+
" set name='"+name+"',title='"+title+"' ,password='"+password+"' "+
"where id='"+id+"' ";
sqlBean db =new sqlBean();
db.executeInsert(sql);
}
public int delete(String id){
int num=0;
String sql="delete from teacher where id ='"+id+"' ";
sqlBean db= new sqlBean();
num=db.executeDelete(sql);
return num;
}
}
[/quote]
在执行这段代码时总是出现如下错误
[quote]
D:\bea\user_projects\domains\mydomain\.\myserver\.wlnotdelete\extract\myserver_appweb_appweb\jsp_servlet\__getteacher.java:181: 'catch' without 'try'
} catch (Throwable __ee) {
^
D:\bea\user_projects\domains\mydomain\.\myserver\.wlnotdelete\extract\myserver_appweb_appweb\jsp_servlet\__getteacher.java:192: '}' expected
^
D:\bea\user_projects\domains\mydomain\.\myserver\.wlnotdelete\extract\myserver_appweb_appweb\jsp_servlet\__getteacher.java:136: 'try' without 'catch' or 'finally'
try { // error page try block
^
3 errors
[/quote]
用Jb检查了,没有出现不对称,求助大家帮帮忙,十分感谢
Nothing 2006-5-26 00:04
说你的try和catch不匹配,不过看你的代码有点乱,搞不好是括号不匹配
[code]
try{
ResultSet rs=db.executeQuery(sql);
if(rs.next()){
f=false;
} else{
f=true;
}
}catch(Exception e){
e.getMessage();
}
[/code]
myjava 2006-5-26 00:24
多谢老大这么晚了还能帮我解答,代码我检查了一下,没有发现不对称的,用Jb9查也是也都匹配。
这段try&catch的代码在另一个类里也使用了,没有问题,但是在这个类里就有问题...
myjava 2006-5-26 03:11
终于找到了问题,原来是jsp引用这个类的时候路径里掉了一个/
唉,粗心害死人...
再次感谢大家