各位请指教编译成bean有错

little23 2004-10-19 03:11:51
package guest;
import java.sql.*;
public class guest
{
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:guest";
private Connection conn = null;
private Statement stmt = null;
ResultSet rs =null;

public guest()
try
{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("guest(): " + e.getMKessage());
}
}

public ResultSet executeQuery(String sql)
{
rs = null ;
try
{
conn = DriverManager.getConnection(sConnStr);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch (SQLException ex)
System.err.println("aq.executeQuery: "+ex.getMessage());
}
return rs;
}

public void executeUpdate(String sql)
{
stmt = null;
rs = null;
try
{
con = DriverManager.getConnection(sConnStr);
stmt = conn.createStatement();
stmt.executeQuery(sql);
stmt.close();
conn.close();
}
catch(SQLException ex)
System.err.ptintln("aq.executeQuery: " + ex.getMessage());
}

public void closeStmt()
{
try
{
stmt.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
将以下编译有 4 个错啊!请指教! 12行 try 错!还有说{ 有错!
public void closeConn()
{
try
{
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
...全文
106 点赞 收藏 18
写回复
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaomineer 2004-10-20
public guest()
{
try
{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("guest(): " + e.getMKessage());
}
}
}这个地方的括号要去掉,加这个括号,这个类就完了,下面的方法没在类里面,他当然要提示你需要一个累了阿,你下面还有错误,你先改这个吧,然后再看报什么错。
回复
little23 2004-10-20
括号搞好了!
剩下一个错误啦!
guest.java:22:'class' or 'interface'expected
public ResultSet executeQuery(String sql)
^
Result R有错??
回复
little23 2004-10-20
package guest;
import java.sql.*;
public class guest
{
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:guest";
private Connection conn = null;
private Statement stmt = null;
ResultSet rs =null;

public guest()
{
try
{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("guest(): " + e.getMKessage());
}
}
}

public ResultSet executeQuery(String sql)
{
rs = null ;
try
{
conn = DriverManager.getConnection(sConnStr);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch (SQLException ex)
{
System.err.println("aq.executeQuery: "+ex.getMessage());
}
return rs;
}

public void executeUpdate(String sql)
{
stmt = null;
rs = null;
try
{
con = DriverManager.getConnection(sConnStr);
stmt = conn.createStatement();
stmt.executeQuery(sql);
stmt.close();
conn.close();
}
catch(SQLException ex)
{
System.err.ptintln("aq.executeQuery: " + ex.getMessage());
}
}

public void closeStmt()
{
try
{
stmt.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}

public void closeConn()
{
try
{
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}

回复
xiaomineer 2004-10-20
把你改完的代码贴出来吧。
回复
little23 2004-10-20
还剩下一个!
guest.java:22:'class' or 'interface'expected
public ResultSet executeQuery(String sql)
回复
little23 2004-10-20
现在剩下这两个错误啊!
guest.java:12:','execpted
try
^
guest.java:22:'class' or 'interface'expected
public ResultSet executeQuery(String sql)
^
回复
little23 2004-10-20
编译出来提示
guest.java:12:','execpted
try
^
guest.java:22:'class' or 'interface'expected
public ResultSet executeQuery(String sql)
^
guest.java:79:'class' or 'interface'expected
}
^
请指教!
回复
little23 2004-10-20
吾好意思啊!大侠!!!
多谢晒!!!!!
因为这是我第一次用jsp的!
做紧个网站会员登陆的后台。
如果有代码希望可以大家分享一下!
回复
tom2005 2004-10-20
ptintln 中的 t 改为 r
回复
snow_jin 2004-10-20
:-D litte的好学精神很让我感动,不过还是忍不住想笑一下。
ptintln--println
建议 用 Eclipse写程序,比较好找错。
回复
little23 2004-10-20
请问你改了些什么呢?
回复
tom2005 2004-10-20
System.err.ptintln("aq.executeQuery: " + ex.getMessage());
改为
System.err.println("aq.executeQuery: " + ex.getMessage());
回复
little23 2004-10-20
多谢!改了几个错误
现在显示一个错误
guest.java:22:cannot resolve symbol
symbol:....
lacation:....
System.err.ptintln("aq.executeQuery: " + ex.getMessage());
^

修改后:
package guest;
import java.sql.*;
public class guest
{
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:guest";
private Connection conn = null;
private Statement stmt = null;
ResultSet rs =null;

public guest()
{
try
{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("guest(): " + e.getMessage());
}
}


public ResultSet executeQuery(String sql)
{
rs = null ;
try
{
conn = DriverManager.getConnection(sConnStr);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch (SQLException ex)
{
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}

public void executeUpdate(String sql)
{
stmt = null;
rs = null;
try
{
conn = DriverManager.getConnection(sConnStr);
stmt = conn.createStatement();
stmt.executeQuery(sql);
stmt.close();
conn.close();
}
catch(SQLException ex)
{
System.err.ptintln("aq.executeQuery: " + ex.getMessage());
}
}

public void closeStmt()
{
try
{
stmt.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}

public void closeConn()
{
try
{
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}



回复
tom2005 2004-10-19
上一个写错了
public void executeUpdate(String sql)
{
stmt = null;
rs = null;
try
{
con = DriverManager.getConnection(sConnStr);
stmt = conn.createStatement();
stmt.executeQuery(sql);
stmt.close();
conn.close();
}
catch(SQLException ex)
这里应加“{”吧
System.err.ptintln("aq.executeQuery: " + ex.getMessage());
这里应加“}”
}
回复
tom2005 2004-10-19
public void executeUpdate(String sql)
{
stmt = null;
rs = null;
try
{
con = DriverManager.getConnection(sConnStr);
stmt = conn.createStatement();
stmt.executeQuery(sql);
stmt.close();
conn.close();
}
catch(SQLException ex)
System.err.ptintln("aq.executeQuery: " + ex.getMessage());
}
回复
tom2005 2004-10-19
public ResultSet executeQuery(String sql)
{
rs = null ;
try
{
conn = DriverManager.getConnection(sConnStr);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch (SQLException ex)
//////////这一行也少了"{"

System.err.println("aq.executeQuery: "+ex.getMessage());
}
return rs;
}
回复
xmbareheaded 2004-10-19
你的程序中:
public guest()
//////////这一行少了"{"
try
{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("guest(): " + e.getMKessage());
}
}
回复
xmbareheaded 2004-10-19
是不是多了一个“}”你再仔细检查一下程序看看
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告