java编译出现需要为class、interface或enum的错误 很郁闷~~!!

来源:百度知道 编辑:UC知道 时间:2024/06/19 10:17:53
我是菜鸟 不怎么懂的 只知道添加了一段语句 就出现了错误 而且都是需要为class、interface或enum的错误 下面附上错误的语句 麻烦各位高手看看
//getBossLog module
public int getBossLog(String bossid) {
Connection con1 = DatabaseConnection.getConnection();
try {
int ret_count = 0;
PreparedStatement ps;
ps = con1.prepareStatement("select count(*) from bosslog where characterid = ? and bossid = ? and lastattempt >= subtime(current_timestamp, '1 0:0:0.0')");
ps.setInt(1, id);
ps.setString(2, bossid);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
ret_count = rs.getInt(1);
} else {
ret_count = -1;
}
rs.close();
ps.close();
return ret_count;
} catch (Exception Ex) {
log.error("Error while read bosslog.", Ex);
return -1;
}
}

//setBossLog module
public void setBossLog(String bossid) {
Connection con1 = DatabaseConnection.getConnection();
try {
PreparedStatement ps;

方法必须定义在类里

class Test{
//这里才能写函数
}

这位朋友,你要是初学者,这样的代码看起来实在是有一点困难。
不过我还是愿意给你解释一下出现错误的原因。
首先:上面的程序代码你决有在关分健字 class 类名

方法体

中写程序代码。
我们写的JAVA程序代码一般都是在这里面写的,你没有这样做,所以出错了需要定义为class的错误。

再者:interface关健这是声明接口的关健字,这里面你用到了接口里的方法,而你没有声明接口,所以会报错。

你要是看不懂出没关系,从头开始学,你一定会成功的,祝你好运!!

where is the class ?