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

📄 javaoperatelongraw.java~20~

📁 用JAVA处理ORACLE中LONGRAW类型字段
💻 JAVA~20~
字号:
package javaopratelongraw;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import oracle.jdbc.driver.*;
import java.text.*;
import javax.swing.*;


/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class javaOperateLongraw
    extends Applet {
  private boolean isStandalone = false;
  Connection conn=null;
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  //Get a parameter value
  public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
        (getParameter(key) != null ? getParameter(key) : def);
  }

  //Construct the applet
  public javaOperateLongraw() {
  }

  //Initialize the applet
  public void init() {
    try {
      Class.forName("oracle.jdbc.driver.OracleDriver");
      //connect the oracle database
    conn = DriverManager.getConnection(
          "jdbc:oracle:thin:@127.0.0.1:1521:hbkj", "system", "manager");


      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  //Component initialization
  private void jbInit() throws Exception {
    jButton1.setBounds(new Rectangle(35, 105, 135, 57));
    jButton1.setText("导入");
    jButton1.addMouseListener(new javaOperateLongraw_jButton1_mouseAdapter(this));
    this.setLayout(null);
    jButton2.setBounds(new Rectangle(35, 186, 138, 53));
    jButton2.setText("导出");
    jButton2.addMouseListener(new javaOperateLongraw_jButton2_mouseAdapter(this));
    this.add(jButton1, null);
    this.add(jButton2, null);
  }

  //Get Applet information
  public String getAppletInfo() {
    return "Applet Information";
  }

  //Get parameter info
  public String[][] getParameterInfo() {
    return null;
  }

  void jButton1_mouseClicked(MouseEvent e) {
//open a file, put the content of file into a bytes array
    try {
      File files = new File("c:\\globe_channels.gif");
      FileInputStream fis = new FileInputStream(files);
      //System.out.println(files.getName());
      this.showStatus(files.getName());
      this.showStatus(Integer.toString( (int) (files.length())));
      ;
      //System.out.println((int)files.length());
      byte[] fl = new byte[ (int) files.length()];
      this.showStatus(Integer.toString(fl.length));
      //System.out.println(fl.length);
      fis.read(fl);

      //use this bytes array to construct a InputStream

      ByteArrayInputStream kk = new ByteArrayInputStream(fl);

      PreparedStatement ps = conn.prepareStatement(
          "INSERT INTO bin_data (name,data)" + "VALUES (?, ?)");

      //set parameters

      ps.setString(1, files.getName());
      ps.setBinaryStream(2, kk, (int) files.length());

      //execute

      ps.executeUpdate();
      fis.close();
      ps.close();

    }
    catch (Exception e1) {

    }

  }

  void jButton2_mouseClicked(MouseEvent e) {
    try {
      // read from the table
      int bytesRead = 0;
      int byteSum = 0;
      byte[] buffer = new byte[8 * 1024];
      FileOutputStream fis2 = new FileOutputStream("c:\\hi_NavCClt.Log");

      PreparedStatement ps2 = conn.prepareStatement("select data from bin_data where name='_NavCClt.Log'");
      ResultSet rs = ps2.executeQuery();
      if (rs != null) {
       while (rs.next()) {
          InputStream is = rs.getBinaryStream(1);
          while ( (bytesRead = is.read(buffer)) != -1) {
            byteSum += bytesRead;
            fis2.write(buffer, 0, bytesRead);
          }
          fis2.close();
     }
        rs.close();
      }
      ps2.close();
      javax.swing.JOptionPane.showMessageDialog(this,"finished","tishi",JOptionPane.YES_NO_CANCEL_OPTION);

    }
    catch (Exception E3) {

    }
  }
}

class javaOperateLongraw_jButton1_mouseAdapter
    extends java.awt.event.MouseAdapter {
  javaOperateLongraw adaptee;

  javaOperateLongraw_jButton1_mouseAdapter(javaOperateLongraw adaptee) {
    this.adaptee = adaptee;
  }

  public void mouseClicked(MouseEvent e) {
    adaptee.jButton1_mouseClicked(e);
  }
}

class javaOperateLongraw_jButton2_mouseAdapter
    extends java.awt.event.MouseAdapter {
  javaOperateLongraw adaptee;

  javaOperateLongraw_jButton2_mouseAdapter(javaOperateLongraw adaptee) {
    this.adaptee = adaptee;
  }

  public void mouseClicked(MouseEvent e) {
    adaptee.jButton2_mouseClicked(e);
  }
}

⌨️ 快捷键说明

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