一个菜鸟问问在编译程序中出现的错误。在线急等啊。拜托啊

maxobj_0 2005-02-04 11:25:38
我在jb8下编译一段程序,出现了这个错误是什么意思,该怎么解决
"beanlogin.java": Error #: 475 : class DBConn is public; must be declared in a file named DBConn.java at line 7, column 8
被便宜的程序是://include required classes
import java.sql.*;

//==========================================
// Define Class DBConn
//==========================================
public class DBConn
{
public String sql_driver = "sun.jdbc.odbc.JdbcOdbcDriver";
public String sql_url = "jdbc:odbc:userdata";
public String sql_DBName = "userdata";
public String user = "";
public String pwd = "";

Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

public boolean setDriver(String drv)
{
this.sql_driver = drv;
return true;
}

public String getDriver()
{
return this.sql_driver;
}

public boolean setUrl(String url)
{
this.sql_url = url;
return true;
}

public boolean setDBName(String dbname)
{
this.sql_DBName = dbname;
return true;
}

public String getDBName()
{
return this.sql_DBName;
}

public boolean setUser(String user)
{
this.user = user;
return true;
}

public String getUser()
{
return this.user;
}

public boolean setPwd(String pwd)
{
this.pwd = pwd;
return true;
}

public String getPwd()
{
return this.pwd;
}

public DBConn()
{
try{
Class.forName(sql_driver);//加载数据库驱动程序
this.conn = DriverManager.getConnection( sql_url,"","");
this.stmt = this.conn.createStatement();
}catch(Exception e){
System.out.println(e.toString());
}
}

//执行查询操作
public ResultSet executeQuery(String strSql)
{
try{
this.rs = stmt.executeQuery(strSql);
return this.rs;
}catch(SQLException e){
System.out.println(e.toString());
return null;
}catch(NullPointerException e){
System.out.println(e.toString());
return null;
}
}

//执行数据的插入、删除、修改操作
public boolean execute(String strSql)
{
try{
if(this.stmt.executeUpdate(strSql) == 0)
return false;
else
return true;
}catch(SQLException e){
System.out.println(e.toString());
return false;
}catch(NullPointerException e){
System.out.println(e.toString());
return false;
}
}

//结果集指针跳转到某一行
public boolean rs_absolute(int row)
{
try{
this.rs.absolute(row);
return true;
}catch(SQLException e){
System.out.println(e.toString());
return false;
}
}

public void rs_afterLast()
{
try{
this.rs.afterLast();
}catch(SQLException e){
System.out.println(e.toString());
}
}

public void rs_beforeFirst()
{
try{
this.rs.beforeFirst();
}catch(SQLException e){
System.out.print(e.toString());
}
}

public void rs_close()
{
try{
this.rs.close();
}catch(SQLException e){
System.out.print(e.toString());
}
}

public void rs_deleteRow()
{
try{
this.rs.deleteRow();
}catch(SQLException e){
System.out.print(e.toString());
}
}

public boolean rs_first()
{
try{
this.rs.first();
return true;
}catch(SQLException e){
System.out.print(e.toString());
return false;
}
}

public String rs_getString(String column)
{
try{
return this.rs.getString(column);
}catch(SQLException e){
System.out.println(e.toString());
return null;
}
}

//此方法用于获取大段文本,
//将其中的回车换行替换为<br>
//输出到html页面
public String rs_getHtmlString(String column)
{
try{
String str1 = this.rs.getString(column);
String str2 = "\r\n";
String str3 = "<br>";
return this.replaceAll(str1,str2,str3);
}catch(SQLException e){
System.out.println(e.toString());
return null;
}
}

//把str1字符串中的str2字符串替换为str3字符串
private static String replaceAll(String str1,String str2,String str3)
{
StringBuffer strBuf = new StringBuffer(str1);
int index=0;
while(str1.indexOf(str2,index)!=-1)
{
index=str1.indexOf(str2,index);
strBuf.replace(str1.indexOf(str2,index),str1.indexOf(str2,index)+str2.length(),str3);
index=index+str3.length();

str1=strBuf.toString();
}
return strBuf.toString();
}

public int rs_getInt(String column)
{
try{
return this.rs.getInt(column);
}catch(SQLException e){
System.out.println(e.toString());
return -1;
}
}

public int rs_getInt(int column)
{
try{
return this.rs.getInt(column);
}catch(SQLException e){
System.out.println(e.toString());
return -1;
}
}

public boolean rs_next()
{
try{
return this.rs.next();
}catch(SQLException e){
System.out.println(e.toString());
return false;
}
}

//判断结果集中是否有数据
public boolean hasData()
{
try{
boolean has_Data = this.rs.first();
this.rs.beforeFirst();
return has_Data;
}catch(SQLException e){
System.out.println(e.toString());
return false;
}
}

public boolean rs_last()
{
try{
return this.rs.last();
}catch(SQLException e){
System.out.println(e.toString());
return false;
}
}

public boolean rs_previous()
{
try{
return this.rs.previous();
}catch(Exception e){
System.out.println(e.toString());
return false;
}
}

//main方法,调试用
public static void main(String args[])
{
try{
DBConn myconn = new DBConn();
//myconn.setDBName("shopping");
//myconn.DBConn();
//myconn.execute("Insert Into tbl_test(id,name) values('10','shandaer')");
//myconn.execute("Update tbl_test set name='yyyyyyyyyyyy' where id=10");
//myconn.execute("Delete from tbl_test where id=1");
ResultSet rs = myconn.executeQuery("select * from tbl_user order by id desc limit 1");
//boolean hasData = myconn.hasData();
//System.out.println("has data:" + hasData);
//rs.first();
while (myconn.rs.next())
{
int id = myconn.rs_getInt("id") + 1;
System.out.print(id);
System.out.println(myconn.rs_getInt("id") + myconn.rs_getString("name"));

//System.out.println('\n' + myconn.rs_getHtmlString("name"));
//System.out.println(myconn.rs.getString("name") + myconn.rs_getInt(1));
}
}catch(Exception e){
System.err.println(e.toString());
}
}

}

...全文
35 4 点赞 打赏 收藏 举报
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
飛⁵⁷²² 2010-05-31
请问各位大侠,这段代码是什么意思啊?
this.rs.absolute(row);
  • 打赏
  • 举报
回复
zhaowinwork 2005-02-04
出错信息说得挺清楚的了。用DBConn.java作为文件名编译。一个java文件里面的public类名就是java文件名。同一个文件只能有一个public类。
  • 打赏
  • 举报
回复
houguojun 2005-02-04
public的类要以类名为文件名
如public class DBConn
应该存为DBConn.java
  • 打赏
  • 举报
回复
maxobj_0 2005-02-04
没有人啊,自己先顶下
  • 打赏
  • 举报
回复
相关推荐
发帖
Java
创建于2007-09-28

4.8w+

社区成员

Java相关技术讨论
申请成为版主
帖子事件
创建了帖子
2005-02-04 11:25
社区公告
暂无公告