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

📄 dvdframe.java

📁 管理dvd碟片的软件
💻 JAVA
字号:
package dvd;

import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import com.borland.jbcl.layout.*;

public class DVDFrame extends JFrame {
  private Connection connection;
  private JTable table;
  private String query = "SELECT * FROM movie_inf ";
  public boolean haverecords;
  public int number;



  public  DVDFrame(Connection   Connection)
  {
    // The URL specifying the Books database to which
    // this program connects using JDBC to connect to a
    // Microsoft ODBC database.
    connection=Connection;
    haverecords=false;
    // Load the driver to allow connection to the database

    getTable();

    setSize( 450, 450);
    if(haverecords==true)
      show();
    else this.dispose();

  }
  public   DVDFrame(Connection   Connection,String sqlquery)
  {
    // The URL specifying the Books database to which
    // this program connects using JDBC to connect to a
    // Microsoft ODBC database.
    connection=Connection;
    haverecords=false;
    // Load the driver to allow connection to the database
    query=sqlquery;
    getTable();

    setSize( 450,450 );

    if(haverecords==true)
      show();
    else this.dispose();

  }

  private void getTable()
  {
    Statement statement;
    ResultSet resultSet;

    try {


      statement = connection.createStatement();
      resultSet = statement.executeQuery( query );
      displayResultSet( resultSet );
      statement.close();
    }
    catch ( SQLException sqlex ) {
      sqlex.printStackTrace();
    }
  }

  private void displayResultSet( ResultSet rs )
      throws SQLException
  {
    // position to first record
    boolean moreRecords = rs.next();


    // If there are no records, display a message
    if ( ! moreRecords ) {
      haverecords=false;
      JOptionPane.showMessageDialog( this, "对不起,本店未存入相关信息,请重新输入" );
      setTitle( "No records to display" );

      return;
    }
    else haverecords=true;

    setTitle( "Informations table from DVD" );

    Vector columnHeads = new Vector();
    Vector rows = new Vector();

    try {
      // get column heads
      ResultSetMetaData rsmd = rs.getMetaData();

      for ( int i = 1; i <= rsmd.getColumnCount(); ++i )
        columnHeads.addElement( rsmd.getColumnName( i ) );

        // get row data
      do {
        number+=1;
        rows.addElement( getNextRow( rs, rsmd ) );
      } while ( rs.next() );

      // display table with ResultSet contents
      table = new JTable( rows, columnHeads );
      JScrollPane scroller = new JScrollPane( table );
      getContentPane().add(scroller, BorderLayout.CENTER );
      validate();
    }
    catch ( SQLException sqlex ) {
      sqlex.printStackTrace();
    }
  }



  private Vector getNextRow( ResultSet rs, ResultSetMetaData rsmd )
      throws SQLException
  {
    Vector currentRow = new Vector();

    for ( int i = 1; i <= rsmd.getColumnCount(); ++i )
      switch( rsmd.getColumnType( i ) ) {
        case Types.VARCHAR:
          currentRow.addElement( rs.getString( i ) );
          break;
        case Types.INTEGER:
          currentRow.addElement(
              new Long( rs.getLong( i ) ) );
          break;
        case Types.CHAR:
          currentRow.addElement( rs.getString(i));
          break;
        case Types.TINYINT:
          currentRow.addElement(
              new Long( rs.getLong( i ) ) );
          break;
        case Types.SMALLINT:
          currentRow.addElement(
              new Long( rs.getLong( i ) ) );
          break;
        default:
          System.out.println( "Type was: " +
                              rsmd.getColumnTypeName( i ) );
          }

        return currentRow;
      }

      public void shutDown()
      {
        try {
          connection.close();
        }
        catch ( SQLException sqlex ) {
          System.err.println( "Unable to disconnect" );
          sqlex.printStackTrace();
        }
      }

      public DVDFrame() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      private void jbInit() throws Exception {
        this.setFont(new java.awt.Font("Dialog", 0, 15));
      }


    }

⌨️ 快捷键说明

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