package blob字段操作;
import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.*;
import java.sql.*;
import java.io.*;
import java.util.*;
public class BlobOperFrame
extends JFrame {
JPanel contentPane;
XYLayout xYLayout1 = new XYLayout();
JButton btnUpdate = new JButton();
JTextField jtfSql = new JTextField();
JLabel lblPict = new JLabel();
JButton btnGet = new JButton();
JButton btnLoadPict = new JButton();
Connection connection = null;
Statement statement = null;
JLabel lblOut = new JLabel();
JTextField jtfEquipName = new JTextField();
JTextField jtfSelect = new JTextField();
public BlobOperFrame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
initForm();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(xYLayout1);
setSize(new Dimension(400, 300));
setTitle("Blob字段操作");
btnUpdate.setText("Update");
btnUpdate.addActionListener(new BlobOperFrame_jButton1_actionAdapter(this));
jtfSql.setText(
"Update fmis04.equ_Equipment set EquipPict = ? where EquipCode = \'111\'");
lblPict.setIcon(null);
lblPict.setText("lblIn");
btnGet.setText("Get");
btnGet.addActionListener(new BlobOperFrame_btnGet_actionAdapter(this));
btnLoadPict.setText("LoadPic");
btnLoadPict.addActionListener(new BlobOperFrame_btnLoadPict_actionAdapter(this));
lblOut.setText("lblOut");
jtfEquipName.setText("jtfEquipName");
jtfSelect.setToolTipText("");
jtfSelect.setText(
"select * from fmis04.equ_Equipment where EquipCode = \'111\'");
contentPane.add(lblPict, new XYConstraints(32, 93, 133, 115));
contentPane.add(lblOut, new XYConstraints(234, 107, 135, 110));
contentPane.add(jtfEquipName, new XYConstraints(230, 90, 128, 21));
contentPane.add(jtfSql, new XYConstraints(3, 6, 381, 32));
contentPane.add(jtfSelect, new XYConstraints(6, 50, 380, 26));
contentPane.add(btnLoadPict, new XYConstraints(63, 199, 75, 22));
contentPane.add(btnUpdate, new XYConstraints(48, 229, 121, 27));
contentPane.add(btnGet, new XYConstraints(224, 224, 98, 31));
}
private void initForm() {
try {
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
String url = "jdbc:db2:EquData";
connection = DriverManager.getConnection(url, "db2admin", "lysdb2");
statement = connection.createStatement();
}
catch (SQLException ex) {
System.out.println("----------SQL Exception SQL错误---------");
while (ex != null) {
System.out.println("Message" + ex.getMessage());
System.out.println("SQLSatate" + ex.getSQLState());
System.out.println("ErrorCode" + ex.getErrorCode());
ex.getNextException();
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public void jButton1_actionPerformed(ActionEvent e) {
String strSql = jtfSql.getText();
/*
try {
PreparedStatement preState = connection.prepareStatement(strSql);
File fileBlob = new File("D:\\BmpIcoJpg\\bmp\\Help.bmp");
int iLength = (int)fileBlob.length();
FileInputStream inStr = new FileInputStream(fileBlob);
preState.setBinaryStream(1, inStr, iLength);
preState.executeUpdate();
}
catch (Exception ex) {
System.out.println("--准备SQL语句出错------");
ex.printStackTrace();
}
*/
Vector vecParam = new Vector();
try {
File fileBlob = new File("D:\\BmpIcoJpg\\bmp\\Help.bmp");
int iLength = (int)fileBlob.length();
FileInputStream inStr = new FileInputStream(fileBlob);
byte bytesParam[] = new byte[iLength];
inStr.read(bytesParam);
vecParam.addElement(bytesParam);
ExecuteBLOBSqlEx(strSql, vecParam);
}
catch (Exception ex) {
System.out.println("--准备SQL语句出错------");
ex.printStackTrace();
}
}
public int ExecuteBLOBSql(String strSql, Object objParam) {
try {
PreparedStatement preState = connection.prepareStatement(strSql);
File fileBlob = new File("D:\\BmpIcoJpg\\bmp\\Help.bmp");
int iLength = (int)fileBlob.length();
FileInputStream fileStr = new FileInputStream(fileBlob);
byte byteArr[] = new byte[iLength];
fileStr.read(byteArr);
System.out.println(String.valueOf(iLength));
FileInputStream strPara = null;
byte bytesPara[];
int iLen = 0;
Vector vecParam = (Vector)objParam;
if (vecParam.size() == 1) {
//Blob blob;
//blob = (Blob)vecParam.elementAt(0);
//strPara = (FileInputStream)vecParam.elementAt(0);
//strPara.reset();
//while( strPara.read() >= 0 ) {
// iLen = iLen + 1;
//}
bytesPara = (byte[])vecParam.elementAt(0);
//preState.setBinaryStream(1, strPara, iLength);
preState.setBytes(1, bytesPara);
}
preState.executeUpdate();
}
catch (Exception ex) {
System.out.println("--执行BlobSQL语句出错------");
ex.printStackTrace();
}
return 0;
}
public int ExecuteBLOBSqlEx(String strSql, Object objParam) {
try {
PreparedStatement preState = connection.prepareStatement(strSql);
byte bytesPara[];
Vector vecParam = (Vector)objParam;
if (vecParam.size() == 1) {
bytesPara = (byte[])vecParam.elementAt(0);
preState.setBytes(1, bytesPara);
}
else if (vecParam.size() > 1) {
for (int i = 0; i < vecParam.size(); i ++) {
bytesPara = (byte[])vecParam.elementAt(i);
preState.setBytes(i + 1, bytesPara);
}
}
preState.executeUpdate();
}
catch (Exception ex) {
System.out.println("--执行BlobSQL语句出错------");
ex.printStackTrace();
}
return 0;
}
public void btnLoadPict_actionPerformed(ActionEvent e) {
//ImageIcon ima = new ImageIcon("D:\\BmpIcoJpg\\bmp\\Help.bmp");
Icon icon = new ImageIcon("D:\\BmpIcoJpg\\bmp\\Help.bmp");
lblPict.setIcon(icon);
lblPict.repaint();
}
public void btnGet_actionPerformed(ActionEvent e) {
String strSql = jtfSelect.getText();
try {
statement = connection.createStatement();
ResultSet rs = statement.executeQuery(strSql);
if (rs.next()) {
Blob blob = rs.getBlob("EquipPict");
byte buffer[] = new byte[ (int) blob.length()];
InputStream in = blob.getBinaryStream();
in.read(buffer);
Icon icon = new ImageIcon(buffer);
lblOut.setIcon(icon);
lblOut.repaint();
jtfEquipName.setText(rs.getString("EquipName"));
}
}
catch (Exception ex) {
System.out.println("--获取数据出错------");
ex.printStackTrace();
}
}
}
class BlobOperFrame_btnGet_actionAdapter
implements ActionListener {
private BlobOperFrame adaptee;
BlobOperFrame_btnGet_actionAdapter(BlobOperFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnGet_actionPerformed(e);
}
}
class BlobOperFrame_btnLoadPict_actionAdapter
implements ActionListener {
private BlobOperFrame adaptee;
BlobOperFrame_btnLoadPict_actionAdapter(BlobOperFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnLoadPict_actionPerformed(e);
}
}
class BlobOperFrame_jButton1_acti
没有合适的资源?快使用搜索试试~ 我知道了~
java,Blob字段操作,将图片或者文件保存到数据库中.zip
共22个文件
class:6个
java:2个
local:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 189 浏览量
2023-02-01
18:41:54
上传
评论
收藏 41KB ZIP 举报
温馨提示
java,Blob字段操作,将图片或者文件保存到数据库中.zip
资源推荐
资源详情
资源评论
收起资源包目录
java,Blob字段操作,将图片或者文件保存到数据库中.zip (22个子文件)
java,Blob字段操作,将图片或者文件保存到数据库中
Blob字段操作
classes
blob字段操作
BlobOperApp.class 1KB
BlobOperFrame_btnLoadPict_actionAdapter.class 753B
BlobOperFrame_btnGet_actionAdapter.class 738B
BlobOperApp$1.class 754B
BlobOperFrame_jButton1_actionAdapter.class 744B
BlobOperFrame.class 7KB
package cache
blob字段操作.dep2 7KB
Blob字段操作.jpx.local~ 3KB
bak
blob字段操作
BlobOperFrame.java~42~ 7KB
BlobOperFrame.java~40~ 7KB
BlobOperFrame.java~36~ 7KB
BlobOperFrame.java~38~ 7KB
BlobOperFrame.java~39~ 7KB
BlobOperFrame.java~37~ 7KB
BlobOperFrame.java~43~ 7KB
BlobOperFrame.java~45~ 8KB
BlobOperFrame.java~44~ 8KB
BlobOperFrame.java~41~ 7KB
src
blob字段操作
BlobOperFrame.java 8KB
BlobOperApp.java 1KB
Blob字段操作.jpx 3KB
Blob字段操作.jpx.local 2KB
H
共 22 条
- 1
资源评论
GZM888888
- 粉丝: 141
- 资源: 2912
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功