已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Java 操作MySql Blob 字段import java.sql.*;import java.io.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;class myImgConnection conn;Statement st;PreparedStatement ps,pu;ResultSet rs;JLabel l1;JFrame f;JFileChooser jf;String fn;JTextField t1,t2;JButton bi,bimg,bf,bp,bn,bl;JPanel p1,p2,p3,p4;myImg()f=new JFrame(图片字段操作);f.setDefaultCloseOperation(3);f.setBounds(100,100,600,500);jf=new JFileChooser(.);Container c=f.getContentPane();c.setLayout(new BorderLayout();p1=new JPanel();p2=new JPanel();p3=new JPanel();p4=new JPanel();p4.setLayout(new BorderLayout();bi=new JButton(插入记录);bf=new JButton(第一条记录);bp=new JButton(上一条记录);bn=new JButton(下一条记录);bl=new JButton(最后条记录);bimg=new JButton(修改照片);t1=new JTextField(10);t2=new JTextField(10);p3.add(t1);p3.add(bi);p3.add(bimg);p2.add(t2);p2.add(p3);p2.add(bf);p2.add(bp);p2.add(bn);p2.add(bl);p4.add(p2,Center);p4.add(p3,South);l1=new JLabel();p1.add(l1);c.add(p1,North);c.add(p4,South);f.setVisible(true);tryClass.forName(com.mysql.jdbc.Driver);conn=DriverManager.getConnection(jdbc:mysql:/127.0.0.1:3306/myschool,root,root);ps=conn.prepareStatement(insert into img values(null,?,?);pu=conn.prepareStatement(Update img set Img=? where SName=?);st=conn.createStatement();rs=st.executeQuery(select * from img);rs.next();mm();catch(ClassNotFoundException ex)catch(SQLException exx)bf.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e) tryrs.first();mm();catch(SQLException ex);bp.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e) tryrs.previous();mm();catch(SQLException ex);bn.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e) tryrs.next();mm();catch(SQLException ex);bl.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e) tryrs.last();mm();catch(SQLException ex)System.out.println(error););bi.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e) InputStream in=null;if(jf.showDialog(f,插入图片)=JFileChooser.APPROVE_OPTION);fn=jf.getSelectedFile().getPath();tryFile f=new File(fn);in=new FileInputStream(f);ps.setString(2,t1.getText().trim();ps.setBinaryStream(1,in,(int)f.length();pu.executeUpdate();rs=st.executeQuery(select * from img);catch(SQLException exx)System.out.println(error1);catch(IOException ex)System.out.println(error2););bimg.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e) InputStream in=null;if(jf.showDialog(f,插入图片)=JFileChooser.APPROVE_OPTION);fn=jf.getSelectedFile().getPath();tryFile f=new File(fn);in=new FileInputStream(f);pu.setBinaryStream(1,in,(int)f.length();pu.setString(2,t2.getText().trim();pu.executeUpdate();rs=st.executeQuery(select * from img);catch(SQLException exx)System.out.println(error1);catch(IOException ex)System.out.println(error2););void mm() throws SQLExceptiont2.setText(rs.getString(2);Blob blob=rs.getBlob(3);if(blob!=nul
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 公司职工岗位管理制度范本(3篇)
- 职业安全管理岗位培训测试题库
- 经典唐诗三百首教学资源合集
- 企业员工健康管理方案及效果评估
- 人力资本投资回报分析报告
- 高校食品安全管理实务操作指南
- 初中美术全册课程教学方案
- 人教版一年级数学课后同步练习
- 施工组织设计与工程造价案例分析
- 2025新能源电池生产行业市场现状供需分析及投资评估规划分析研究报告
- 2025山西临汾安泽县人力资源和社会保障局开发招用公益性岗位40人备考题库附答案解析
- 英威腾变频器培训课件
- 职业技能鉴定初级通信终端设备维修工考核试题
- 2025DAS指南:成人未预料困难气管插管的管理解读课件
- 户内燃气抢修培训课件
- 企业报税实操课件
- 克拉玛依介绍
- 2025至2030中医医院行业项目调研及市场前景预测评估报告
- 2026年高考作文备考之议论文主体段落写作指导:“五层结构法”详解
- 2025年学法考试广东考场一试题及答案本
- 雨课堂在线学堂《全球化与世界空间》单元考核测试答案
评论
0/150
提交评论