blob和clob类型数据怎么插入数据库
- 一般情况下,数据库中不会直接存音频文件,而是存储字节码文件
- 但以下告诉我们blob和clod类型数据怎么插入数据库——通过swt编写界面添加
1.sql语句
public class dao {DbHelper db = new DbHelper();/*** 修改用户头像* @param aid* @param pwd* @return* @throws Exception*/public int updateUserImage(String id,byte[]images) throws Exception{String sql="update ps_user set u_head =? where u_id=?";return db.update(sql,images,id);}/*** 修改歌手头像* @param aid* @param images* @return* @throws Exception*/public int updateSingerImage(String id,byte[]images) throws Exception{String sql="update ps_singer set s_image =? where s_id=?";return db.update(sql,images,id);}
}
2.主窗口跳转
public class add {protected Shell shell;/*** Launch the application.* @param args*/public static void main(String[] args) {try {add window = new add();window.open();} catch (Exception e) {e.printStackTrace();}}/*** Open the window.*/public void open() {Display display = Display.getDefault();createContents();shell.open();shell.layout();while (!shell.isDisposed()) {if (!display.readAndDispatch()) {display.sleep();}}}/*** Create contents of the window.*/protected void createContents() {shell = new Shell();shell.setSize(450, 300);shell.setText("SWT Application");Button button = new Button(shell, SWT.NONE);button.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {//窗口跳转adddateimage Add=new adddateimage(shell,SWT.MIN|SWT.APPLICATION_MODAL);Add.open();}});button.setBounds(141, 103, 114, 34);button.setText("跳转");}
}
3.实现插入操作
public class adddateimage extends Dialog {protected Object result;protected Shell shell;private Label label_1;private String filepath="";//文件路径dao d = new dao();private Text text_userid;private Text text_singerid;/*** Create the dialog.* @param parent* @param style*/public adddateimage(Shell parent, int style) {super(parent, style);setText("SWT Dialog");}/*** Open the dialog.* @return the result*/public Object open() {createContents();shell.open();shell.layout();Display display = getParent().getDisplay();while (!shell.isDisposed()) {if (!display.readAndDispatch()) {display.sleep();}}return result;}/*** Create contents of the dialog.*/private void createContents() {shell = new Shell(getParent(), getStyle());shell.setSize(707, 661);shell.setText(getText());Label label = new Label(shell, SWT.NONE);label.addMouseListener(new MouseAdapter() {@Overridepublic void mouseDoubleClick(MouseEvent e) {//创建文件对话框FileDialog fd = new FileDialog(shell);fd.setFilterPath("E:\\");//设置选择文件类型fd.setFilterExtensions(new String[]{"*.*"});filepath=fd.open();//返回图片的绝对路径if(null==filepath||"".equals(filepath)){label_1.setText("未选择中图片");return ;}//文件路径try {//将选中图片设置到label中File file = new File(filepath);InputStream in = new FileInputStream(file);Image image = new Image(Display.getDefault(),in);label.setImage(image);label_1.setText("图片上传成功");YcUtil.imageSize(label);} catch (Exception e1) {e1.printStackTrace();}}});label.setImage(SWTResourceManager.getImage(adddateimage.class, "/com/cj/image/音乐.png"));label.setBounds(180, 54, 308, 243);label_1 = new Label(shell, SWT.NONE);label_1.setBounds(266, 345, 259, 24);label_1.setText("双击");Button btn_useradd = new Button(shell, SWT.NONE);btn_useradd.addMouseListener(new MouseAdapter() {@Overridepublic void mouseDoubleClick(MouseEvent e) {String id = text_userid.getText().trim();File file=new File(filepath);InputStream in=null;try {in=new FileInputStream(file);byte[] images=new byte[(int) file.length()];in.read(images);int result = d.updateUserImage(id, images);if(result<=0){MessageDialog.openError(shell, "错误提示", "添加失败");}} catch (Exception e1) {e1.printStackTrace();}finally{if(null!=in){try {in.close();} catch (IOException e1) {e1.printStackTrace();}}}}});btn_useradd.addSelectionListener(new SelectionAdapter() {});btn_useradd.setBounds(43, 480, 114, 34);btn_useradd.setText("添加用户");text_userid = new Text(shell, SWT.BORDER);text_userid.setBounds(77, 434, 106, 30);Label lblId = new Label(shell, SWT.NONE);lblId.setBounds(10, 437, 61, 24);lblId.setText("IDuser");Label lblIdsinger = new Label(shell, SWT.NONE);lblIdsinger.setText("IDsinger");lblIdsinger.setBounds(210, 434, 78, 24);text_singerid = new Text(shell, SWT.BORDER);text_singerid.setBounds(294, 434, 106, 30);Button btn_singeradd = new Button(shell, SWT.NONE);btn_singeradd.addMouseListener(new MouseAdapter() {@Overridepublic void mouseDoubleClick(MouseEvent e) {String id = text_singerid.getText().trim();File file=new File(filepath);InputStream in=null;try {in=new FileInputStream(file);byte[] images=new byte[(int) file.length()];in.read(images);int result = d.updateSingerImage(id, images);if(result<=0){MessageDialog.openError(shell, "错误提示", "添加失败");}} catch (Exception e1) {e1.printStackTrace();}finally{if(null!=in){try {in.close();} catch (IOException e1) {e1.printStackTrace();}}}}});btn_singeradd.setText("添加歌手");btn_singeradd.setBounds(249, 480, 114, 34);}
}
blob和clob类型数据怎么插入数据库相关推荐
- mysql数据库clob类型数据_JDBC读写MySQL的BLOB和CLOB类型数据(带代码)
JDBC对LOB的读写 在JDBC中提供了java.sql.Blob和java.sql.Clob两个类分别代表BLOB和CLOB数据 •BLOB(Binary Large Object):用于存储大量 ...
- python连接oracle数据库 插入clob类型数据
python连接oracle数据库 插入clob类型数据 连接数据库 import cx_Oracle as cx #导入模块 con = cx.connect('root', 'root123', ...
- Spring JDBC-使用Spring JDBC获取本地连接对象以及操作BLOB/CLOB类型数据
概述 如何获取本地数据连接 示例从DBCP数据源中获取Oracle的本地连接对象 相关接口操作 LobCreator LobHandler 插入LOB类型的数据 以块数据的方式读取LOB数据 以流数据 ...
- mysql 读取clob数据类型_谈谈有关各数据库Blob、Clob类型字段的读取、保存更新
经常有人谈到Blob类型字段的读写问题,我也来说两句. 最近在写一些东西,对常用数据库的数据类型.函数等作了一些比较,也写了许多了的测试代码,以下是我测试的结果: 测试数据库: MS Sql Serv ...
- java将clob类型文件写到磁盘_Java对Oracle中Clob类型数据的读取和写入
Java对Oracle中Clob数据类型是不能够直接插入的,但是可以通过流的形式对clob类型数据写入或者读取,网上代码并不算特别多,讲的 Java对Oracle中Clob数据类型是不能够直接插入的, ...
- hibernate clob mysql_Hibernate操作Clob类型数据
在POJO中字符串大对象可以声明成一个java.lang.String或java.sql.Clob类型. 当程序从数据库中加载Clob类型数据时,仅仅加载了一个Clob类型的数据的逻辑指针.我们需要通 ...
- 5.4.1 映射Blob和Clob类型@Lob
通常,可以在数据库中保存诸如图片,长文本类型的数据.这种类型的数据一般是保存成Blob和Clob类型. 这两种类型的数据可以通过使用@Lob属性来标注.例如CustomerEO实体增加了一个属性por ...
- clob在java里的类型_Java对Oracle中Clob类型数据的读取和写入(转)
Java对Oracle中Clob数据类型是不能够直接插入的,但是可以通过流的形式对clob类型数据写入或者读取,网上代码并不算特别多,讲的也不是很清楚,我对网上资料进行了整理和总结,具体看代码: 写入 ...
- 大量数据批量插入数据库
大量数据批量插入数据库 前言 工作时遇到了大量数据需要插入到数据库的情况,一条条的插入速度慢效率低下,不能满足需求,为了解决此问题采用了sql中使用foreach,并在service中设置批量来进行批 ...
- 往Oracle数据库中插入NCLOB/CLOB类型数据
最近因为业务需求开发了一个接口用于接收数据,但是总有一些数据报出ORA-01704:字符串文字太长错误.仔细排查后发现,竟然是NCLOB类型字段提示这个错误.NCLOB存储空间有4G,怎么也想不明白为 ...
最新文章
- Access和SQL server开启表间关系,并实现更新或删除母表数据自动更新或删除子表数据...
- git 无法拉取项目,本地ping不通github的解决办法(详解)
- 老子今天不加班,程序员也需要自由
- asp.net core 教程(六)-中间件
- php购物网站类的继承和多态,类的继承与多态
- MySQL 数据库优化设计
- 马斯克又把吹过的牛实现!“无聊公司”测试隧道首次亮相,时速高达80公里...
- 微信小程序自定义弹窗组件
- Android面试题整理
- Linux系统管理----centos7系统进程管理
- 中国社会为何多犬儒?
- win10电脑鼠标右键菜单中的选项提示没有关联的应用应用来执行操作以及工具栏点击没反应的解决方案
- 树莓派显示器分辨率的调整,黑边的修改方法
- Vue3能用到生产环境了吗?
- 数据结构C语言版(答案)
- 商业模式新生代_精读商业模式新生代之“多边平台式商业模式”
- python直接下载图片到内存
- python学习dya4
- 134.如何进行实时计算
- .net程序员工作两年总结
热门文章
- 使用AccessibilityService(无障碍服务)自动完成手机设置功能
- react中使用eslint+prettier+airbnb校验代码风格
- 合肥工业大学C语言提交作业,合肥工业大学C语言题库程序设计.doc
- XCTF-攻防世界CTF平台-Web类——19、mfw(.Git源代码泄露、php的assert断言)
- CentOS7.5安裝配置多协议下载器Aria2
- 乐得瑞LDR6282B 支持双C口盲插便携显示器驱动板方案
- Unity按钮按下、抬起的反应
- linux虚拟机cents7配置静态ip
- 基于SSM的培训班管理系统
- Microsoft Word 论文编排技巧