C/S 架构  
jBulider中 DataExpress 
中的Database 的
上司要求用那些控件。
(在配置好连接的前提下).         Database db=new Database();
         db.createStatement();
         db.executeStatement(sql);
                    这里爆错。于是乎我想到了,用java.sql.Statement 与之连接。经过试验,还是不能。
能否给个思路 解决这个问题?

解决方案 »

  1.   

    使用DataExpress的话,用QueryDataSet等不是方便很多吗?为什么要用java.sql.Statement呢?如果非要用也是可以的呀
      

  2.   

    db.createStatement();返回的就是java.sql.Statement嘛强烈建议先去看看Borland的帮助后在提问!
      

  3.   

    db.executeStatement(sql); 这里爆错。 1 编译能通过?
    2 什么错? 把异常贴上来!
      

  4.   


    直接报,在编译的时候。我是按照B/S连接数据库的 思路的。See com.borland.dx.dataset.DataSetException error code:  BASE+39
    com.borland.dx.dataset.DataSetException: Operation cannot be performed on an open DataSet.  Close the DataSet first.
    at com.borland.dx.dataset.DataSetException.c(Unknown Source)
    at com.borland.dx.dataset.DataSetException.r(Unknown Source)
    at com.borland.dx.dataset.StorageDataSet.n(Unknown Source)
    at com.borland.dx.dataset.DataSet.setMasterLink(Unknown Source)谢谢
      

  5.   

    我几年前做过一个类似的C/S系统,在登录时我好像是从database中获取的java.sql.Connection,然后进行操作的。现在手上没代码了,大概如此。
      

  6.   

    上边的是程序出错了。我重新弄的一个。
    看这个
    //这个是from
    package untitled1;import java.awt.*;
    import javax.swing.*;
    import java.awt.Rectangle;
    import com.borland.dx.sql.dataset.Database;
    import com.borland.dx.sql.dataset.ConnectionDescriptor;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;public class Frame1
        extends JFrame {
      JPanel contentPane;
      JButton jButton1 = new JButton();
      JButton jButton2 = new JButton();
      JTextField jTextField1 = new JTextField();
      JLabel jLabel1 = new JLabel();
      JTextField jTextField2 = new JTextField();
      JLabel jLabel2 = new JLabel();
      JLabel jLabel3 = new JLabel();
      Database database1 = new Database();
      public Frame1() {
        try {
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          jbInit();
        }
        catch (Exception exception) {
          exception.printStackTrace();
        }
      }  /**
       * Component initialization.
       *
       * @throws java.lang.Exception
       */
      private void jbInit() throws Exception {
        contentPane = (JPanel) getContentPane();
        contentPane.setLayout(null);
        setSize(new Dimension(400, 300));
        setTitle("Frame Title");
        jButton1.setBounds(new Rectangle(80, 191, 83, 25));
        jButton1.setText("CANNEL");
        jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
        jButton2.setBounds(new Rectangle(172, 189, 83, 25));
        jButton2.setText("ENSURE");
        jTextField1.setText("jTextField1");
        jTextField1.setBounds(new Rectangle(170, 83, 72, 21));
        jLabel1.setText("PASSWORD:");
        jLabel1.setBounds(new Rectangle(79, 45, 42, 15));
        jTextField2.setText("jTextField2");
        jTextField2.setBounds(new Rectangle(169, 41, 72, 21));
        jLabel2.setText("NAME:");
        jLabel2.setBounds(new Rectangle(84, 85, 42, 15));
        jLabel3.setText("jLabel3");
        jLabel3.setBounds(new Rectangle(106, 145, 42, 15));
        database1.setConnection(new ConnectionDescriptor(
            "jdbc:mysql://localhost:3306/test?characterEncoding=utf-8", "root",
            "pass", false, "com.mysql.jdbc.Driver"));
        contentPane.add(jButton2);
        contentPane.add(jTextField2);
        contentPane.add(jTextField1);
        contentPane.add(jLabel2);
        contentPane.add(jLabel1);
        contentPane.add(jLabel3);
        contentPane.add(jButton1);
      }  public void jButton1_actionPerformed(ActionEvent e) {
        database1.createStatement();
        int i=database1.executeStatement("select * from users");//返回对数据库影响到的行
        System.out.println(i);
      }
    }class Frame1_jButton1_actionAdapter
        implements ActionListener {
      private Frame1 adaptee;
      Frame1_jButton1_actionAdapter(Frame1 adaptee) {
        this.adaptee = adaptee;
      }  public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
      }
    }
    //这个是报的错Exception in thread "AWT-EventQueue-0" See com.borland.dx.dataset.DataSetException error code:  BASE+66
    com.borland.dx.dataset.DataSetException: Can not issue SELECT via executeUpdate().
    at com.borland.dx.dataset.DataSetException.a(Unknown Source)
    at com.borland.dx.dataset.DataSetException.throwException(Unknown Source)
    at com.borland.dx.dataset.DataSetException.SQLException(Unknown Source)
    at com.borland.dx.sql.dataset.Database.executeStatement(Unknown Source)
    java.sql.SQLException: Can not issue SELECT via executeUpdate().
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
    at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1329)
    at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1290)
    at com.borland.dx.sql.dataset.Database.executeStatement(Unknown Source)
      

  7.   

    大哥别给我好像哦,我弄了2天了还没弄好。database可以直接数据库吗?
    或者说要转型成 java.sql.Connection? 回忆下哦。    
      谢谢 
      

  8.   

    public void jButton1_actionPerformed(ActionEvent e) {
        database1.createStatement();
        int i=database1.executeStatement("select * from users");//返回对数据库影响到的行
        System.out.println(i);
      } 
    改为
    public void jButton1_actionPerformed(ActionEvent e) {
        java.sql.Statement stmt = database1.createStatement();
        java.sql.ResultSet rs = stmt.executeQuery("select * from users");
        int i;
        if (rs.last()) i = rs.getRow(); else i = 0;
        System.out.println(i);
    }
    试试。
      

  9.   

    我自己当时肯定是用database.getJdbcConnection()获取java.sql.Connection后操作的,只不过现在没有现成的源码了。