如果要实现mysql插入Clob字段,应该采用什么方法呢?下面这个例子就将为您演示如何实现mysql插入Clob字段的方法,供您参考。

创新互联专注于网站建设|网站维护|优化|托管以及网络推广,积累了大量的网站设计与制作经验,为许多企业提供了网站定制设计服务,案例作品覆盖成都会所设计等行业。能根据企业所处的行业与销售的产品,结合品牌形象的塑造,量身制作品质网站。
- import java.io.*;
 - import java.sql.*;
 - public class DBTest {
 - public static void main(String[] args) {
 - String driver = "com.mysql.jdbc.Driver";
 - String url = "jdbc:mysql://localhost:3306/upload?useUnicode=true&characterEncoding=Big5";
 - String user = "caterpillar";
 - String password = "123456";
 - try {
 - Class.forName(driver);
 - Connection conn = DriverManager.getConnection(url, user, password);
 - File file = new File("./logo_phpbb.jpg");
 - int length = (int) file.length();
 - InputStream fin = new FileInputStream(file);
 - PreparedStatement pstmt = conn.prepareStatement(
 - "INSERT INTO files VALUES(?, ?)");
 - pstmt.setString(1, "Logo");
 - pstmt.setBinaryStream (2, fin, length);
 - pstmt.executeUpdate();
 - pstmt.clearParameters();
 - pstmt.close();
 - fin.close();
 - Statement stmt = conn.createStatement();
 - ResultSet result = stmt.executeQuery("SELECT * FROM files");
 - result.next();
 - String description = result.getString(1);
 - Blob blob = result.getBlob(2);
 - System.out.println("描述:" + description);
 - FileOutputStream fout = new FileOutputStream("./logo_phpbb_2.jpg");
 - fout.write(blob.getBytes(1, (int)blob.length()));
 - fout.flush();
 - fout.close();
 - stmt.close();
 - conn.close();
 - }
 - catch(ClassNotFoundException e) {
 - System.out.println("找不到驱动");
 - e.printStackTrace();
 - }
 - catch(SQLException e) {
 - e.printStackTrace();
 - }
 - catch(IOException e) {
 - e.printStackTrace();
 - }
 - }
 - }
 
mysql插入Clob字段的实例介绍。
【编辑推荐】
常见MySql字段的默认长度
mysql中int数据类型长度的问题
MySQL中INSERT的一般用法
修改mysql字段顺序的方法
mysql添加删除主键的方法
                分享题目:mysql插入Clob字段的实例
                
                文章来源:http://www.csdahua.cn/qtweb/news45/87895.html
            
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网