⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parameterrowframe.java~55~

📁 jbuilder2006一书的所有源代码
💻 JAVA~55~
字号:
package dataexpress;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.dx.sql.dataset.*;
import com.borland.dx.dataset.*;
import com.borland.dbswing.*;

public class ParameterRowFrame extends JFrame implements ActionListener {
  JPanel contentPane;
  BorderLayout borderLayout1 = new BorderLayout();
  Database database1 = new Database();
  QueryDataSet queryDataSet1 = new QueryDataSet();
  ParameterRow parameterRow1 = new ParameterRow();
  Column id = new Column();
  Column categoryName = new Column();
  TableScrollPane tableScrollPane1 = new TableScrollPane();
  JdbTable jdbTable1 = new JdbTable();
  JPanel jPanel1 = new JPanel();
  JLabel jLabel1 = new JLabel();
  JTextField jTextField1 = new JTextField();
  JLabel jLabel2 = new JLabel();
  JTextField jTextField2 = new JTextField();
  JButton jButton1 = new JButton();

  public ParameterRowFrame() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception  {
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(borderLayout1);
    this.setSize(new Dimension(400, 300));
    this.setTitle("ParameterRow示例");
    //建立与SQLServer的books数据库的联接
    database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor(
        "jdbc:microsoft:sqlserver://bemyfriend:1433;DatabaseName=books", "sa",
        "", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver"));
    //设置id参数列
    id.setColumnName("id");
    id.setDataType(com.borland.dx.dataset.Variant.INT);
    id.setDefault("1");
    id.setPreferredOrdinal(0);
    id.setSqlType(0);
    //设置categoryName参数列
    categoryName.setColumnName("categoryName");
    categoryName.setDataType(com.borland.dx.dataset.Variant.STRING);
    categoryName.setDefault("%类别%");
    categoryName.setPreferredOrdinal(1);
    categoryName.setSqlType(0);
    //定义参数类的参数列
    parameterRow1.setColumns(new Column[] {id, categoryName});
    //设置query属性,加入ParameterRow类
    queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(
        database1,
        "select * from bookcategory where id >= :id and categoryName like " +
        ":categoryName", parameterRow1, true, Load.ALL));
    jdbTable1.setDataSet(queryDataSet1);
    jLabel1.setText("序号:");
    jLabel2.setText("   类别名字:");
    jButton1.setText("查询");
    jButton1.addActionListener(this);
    jPanel1.add(jLabel1, null);
    jPanel1.add(jTextField1, null);
    jPanel1.add(jLabel2, null);
    jPanel1.add(jTextField2, null);
    jPanel1.add(jButton1, null);
    tableScrollPane1.getViewport().add(jdbTable1, null);
    contentPane.add(tableScrollPane1, BorderLayout.CENTER);
    contentPane.add(jPanel1, BorderLayout.NORTH);
  }

  protected void processWindowEvent(WindowEvent e) {
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }
  public void actionPerformed(ActionEvent e) {
    //创建id和categoryName
    int id = 0;
    String categoryName = "%类别%";
    //获取序号值
    try {
      id = Integer.parseInt(jTextField1.getText());
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
    //获取类别值
    categoryName = jTextField2.getText();
    //设置参数类的参数值
    parameterRow1.setInt("id", id);
    parameterRow1.setString("categoryName", categoryName);
    //显示查询后的数据
    queryDataSet1.refresh();
    //在编辑框重新显示查询价格
    lowPriceTextField.setText(String.valueOf(lowPrice));
    highPriceTextField.setText(String.valueOf(highPrice));
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -