写的很好,不过还是要提一个建议:
public int insert(String strSQL)
{
if(stmt == null)
return -1; int iRtn = 0; try
{
iRtn = stmt.executeUpdate(strSQL);
}
catch(Exception e)
{
return -1;
} return iRtn;
}//
方法本身是没有问题,如果发生异常,返回-1,其他人在调用时如果返回值是-1就知道调用失败,但是具体是什么错误对于他来说:很是迷茫,他不知道是数据不合法,或是字段不够长,或是其它原因所以对于这种底层的方法最好是将异常抛出,否则别人在调试的时候只能去猜测原因。

解决方案 »

  1.   

    数据update等以后不调用close么?要客户端调用?看不太清楚,好像close没有包装进来,应该包装进来吧,对这个的处理其实是比较的麻烦,客户端也比较容易出问题。
      

  2.   

    1. 用private
    private Connection conn = null;
    private Statement stmt = null;
    private ResultSet rs = null;2. public sqlUtil()里什么都不用干,因为用户new一个类时,并不总是想要马上连接3. getConnection(String strDriverName, String strURL, String strUserName, String strPassword)返回Connection
    并提供缺省设置,即
    public Connection getConection(){
       return getConnection(构造函数里的设置放在这里);
    }
    getStatement返回Statement
    4. 如upc_chenli(chenli)所说,定义自己的Exception类,把return -1、有需要的地方 throw RuntimeException
      或者在函数头声明throws5. public int getRow()有问题,
    rs.last();
    iRowNum = rs.getRow();
    rs.first();
    影响了用户的游标!!6.
    public boolean next()
    {
    try
    {
    if(!rs.next())
    return false;
    }
    catch(SQLException e)
    {
    return false;
    } return true;
    }
    可改为: try{
    return rs.next();
    }catch(SQLException e){
    return false;
    }
    其它也有类似的地方
    呀呀,不说了,我很菜,不妥之处请多多包涵。谢谢!