新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
mysql插入Clob字段的實(shí)例
如果要實(shí)現(xiàn)mysql插入Clob字段,應(yīng)該采用什么方法呢?下面這個(gè)例子就將為您演示如何實(shí)現(xiàn)mysql插入Clob字段的方法,供您參考。

創(chuàng)新互聯(lián)專注于網(wǎng)站建設(shè)|網(wǎng)站維護(hù)|優(yōu)化|托管以及網(wǎng)絡(luò)推廣,積累了大量的網(wǎng)站設(shè)計(jì)與制作經(jīng)驗(yàn),為許多企業(yè)提供了網(wǎng)站定制設(shè)計(jì)服務(wù),案例作品覆蓋成都會(huì)所設(shè)計(jì)等行業(yè)。能根據(jù)企業(yè)所處的行業(yè)與銷售的產(chǎn)品,結(jié)合品牌形象的塑造,量身制作品質(zhì)網(wǎng)站。
- 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("找不到驅(qū)動(dòng)");
- e.printStackTrace();
- }
- catch(SQLException e) {
- e.printStackTrace();
- }
- catch(IOException e) {
- e.printStackTrace();
- }
- }
- }
mysql插入Clob字段的實(shí)例介紹。
【編輯推薦】
常見(jiàn)MySql字段的默認(rèn)長(zhǎng)度
mysql中int數(shù)據(jù)類型長(zhǎng)度的問(wèn)題
MySQL中INSERT的一般用法
修改mysql字段順序的方法
mysql添加刪除主鍵的方法
分享文章:mysql插入Clob字段的實(shí)例
分享路徑:http://www.fisionsoft.com.cn/article/cdijigh.html


咨詢
建站咨詢
