VE-runtime-1.2.3_jem.zip
GEF-runtime-3.2.zip
emf-sdo-runtime-2.2.0.zip
eclipse-SDK-3.2.2-win32.zip
我用这四个版本
制作gui时为什么不太稳定
因为都是新下的preferences中有什么需要设置下,去掉不需要的功能,能让eclipse更好的运行
还有就是在写连接数据库的代码时像这样的函数
private void showFirst(){
String sql1="SELECT * FROM accountsubject WHERE accountcode='"+jTable.getValueAt(0, 0)+"'";
rs=dB.executeQuery(sql1);
try {
if(rs.next()){
showSubject(rs);
}
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}在编辑过程中就会弹出连接失败的对话框
就是下面查询函数的JOptionPane.showMessageDialog(null,"更新数据库失败6!","错误提示",JOptionPane.ERROR_MESSAGE);
语句
public void executeUpdate(String sql){
try{
if(con == null)
close();
connect();
stmt.executeUpdate(sql);
//JOptionPane.showMessageDialog(null,"更新成功!","提示",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception e){
JOptionPane.showMessageDialog(null,"更新数据库失败6!","错误提示",JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}finally{
close();
}
}
程序运行时一切正常的,为什么编辑的时候会出这个错误

解决方案 »

  1.   

    if(con == null) 应该是if(con != null) 吧.
      

  2.   

    if(con == null) 
       close();
      

  3.   

    关闭资源的时候加上try()catch(){}块。
      

  4.   

    if(con == null) 
    close(); 
    connect(); 
    stmt.executeUpdate(sql); 
    //JOptionPane.showMessageDialog(null,"更新成功!","提示",JOptionPane.INFORMATION_MESSAGE); 
    } zhe li neng zhi xing ma ???
      

  5.   

    没有异常,只是编辑的时候老出
    JOptionPane.showMessageDialog(null,"更新数据库失败6!","错误提示",JOptionPane.ERROR_MESSAGE);
    的对话框  我也没有运行 
    谢谢各位了  帮我看看数据库的这个类有什么问题吧,应为还在学习,没有专业的编程经验,我的这个类我觉得问题不小
    希望各位给我指点下import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;import javax.sql.rowset.CachedRowSet;
    import javax.swing.JOptionPane;
    public class DBOperation {
    // String url = "jdbc:mysql://localhost/LibraryManagementSystem"; // @jve:decl-index=0:
    // String url = "jdbc:mysql://localhost:3306/LibraryManagementSystem?useUnicode=true&characterEncoding=GB2312"; // @jve:decl-index=0:
    String url=null;
    String user = null; // @jve:decl-index=0: String psd = null; // @jve:decl-index=0:

    Statement stmt=null;

    String host=null;

    Connection con=null;

    ResultSet resultset=null;

    CachedRowSet rowSet=null;

    Configuration cf = new Configuration(System.getProperty("user.dir")+"\\config.properties");

    DBOperation(){
          user = cf.getValue("user");
          psd = cf.getValue("password");
          host=cf.getValue("host");
          url="jdbc:mysql://"+host+":3306/financialmanagementsystem?useUnicode=true&characterEncoding=GB2312";
    try {
    Class.forName("org.gjt.mm.mysql.Driver");
    } catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    JOptionPane.showMessageDialog(null,"加载数据库驱动器失败!","错误提示",JOptionPane.ERROR_MESSAGE);
    }
    }


    //建立连接
    void connect(){ try {
    con = DriverManager.getConnection(url,user,psd);
    stmt = con.createStatement();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    JOptionPane.showMessageDialog(null,"连接数据库失败!","错误提示",JOptionPane.ERROR_MESSAGE);
    }
    }


        /**
         * 关闭连接
         * 
         */
        public void close(){
            try{            if(con != null) con.close();
                if(stmt != null) stmt.close();
            }catch(Exception e){
    JOptionPane.showMessageDialog(null,"关闭数据库连接失败!","错误提示",JOptionPane.ERROR_MESSAGE);
            }
        }
        
    //查询函数
    public CachedRowSet executeQuery(String sql){
    try{
    rowSet = new com.sun.rowset.CachedRowSetImpl();
    if(con==null)
    close();
    connect();
    resultset = stmt.executeQuery(sql);
    rowSet.populate(resultset);
    }
    catch(Exception e){
    //JOptionPane.showMessageDialog(null,"数据库查询失败5!","错误提示",JOptionPane.ERROR_MESSAGE);
    e.printStackTrace();
    }finally{
    close();
    }

    return rowSet;
    }


    //更新函数
    public void executeUpdate(String sql){
    try{
    if(con == null)
    close();
    connect();
    stmt.executeUpdate(sql);
    //JOptionPane.showMessageDialog(null,"更新成功!","提示",JOptionPane.INFORMATION_MESSAGE);
    }
    catch(Exception e){
    // JOptionPane.showMessageDialog(null,"更新数据库失败6!","错误提示",JOptionPane.ERROR_MESSAGE);
    e.printStackTrace();
    }finally{
    close();
    }
    }
        
    }
      

  6.   

    if(con == null) 
    close(); 
    connect(); 
    stmt.executeUpdate(sql); 
    if(con==null) 
    close(); 
    connect(); 
    resultset = stmt.executeQuery(sql); 这两处的close()我知道放的很不是地方,可是不放的话,有时回提示stmt没有关闭