JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » JDBC/SQL討論區 » MySQL  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 請問有辦法將照片(jpg.gif...)存入mysql嗎? [精華]
x3711699





發文: 148
積分: 4
於 2004-02-18 21:22 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
如題,
不知道技術上是否能做到?
如果可,那是會以什麼資料型態存入?
還有,是否會有容量的限制?


reply to postreply to post
作者 Re:請問有辦法將照片(jpg.gif...)存入mysql嗎? [Re:x3711699]
chuang5089





發文: 254
積分: 0
於 2004-02-19 00:37 user profilesend a private message to usersend email to chuang5089reply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.io.*;
public class First {
 
  public static String str ;
  public First() {
 
  }
  public void File(){
    int n;
 
      try {
      // read
       FileInputStream file1 = new FileInputStream("code.jpg");
 
        while ((n = file1.available()) > 0) {
          byte[] b = new byte[n];
          int result = file1.read(b);
          if (result == -1)break;
          str = new String(b);
         // System.out.print(str);
        } //end while
        file1.close();
 
        // write
        FileOutputStream fo = new FileOutputStream("c.htm");
        fo.write(str.getBytes());
        System.out.write('\t');
        fo.flush();
 
        // may you need some mothod insert database
 
      }catch (IOException e) {
        System.err.println(e.toString());
 
      } //end try/catch
 
  }//end File
 
  public static void main(String[] args) {
    First first1 = new First();
    first1.File();
 
  }
 
}
 


anthonychen edited on 2004-02-19 00:52
reply to postreply to post
作者 Re:請問有辦法將照片(jpg.gif...)存入mysql嗎? [Re:x3711699]
anthonychen

外線交給我

版主

發文: 2033
積分: 8
於 2004-02-19 00:59 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
可以將圖檔存入MySQL中,資料型態是BLOB。
不過MySQL的BLOB大小有64K,如果有大圖檔需求可以使用MEDIUMBLOB or LONGBLOB。


reply to postreply to post
作者 Re:請問有辦法將照片(jpg.gif...)存入mysql嗎? [Re:x3711699]
x3711699





發文: 148
積分: 4
於 2004-02-19 13:16 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
多謝!! 感激不盡!!

reply to postreply to post
作者 Re:請問有辦法將照片(jpg.gif...)存入mysql嗎? [Re:anthonychen]
marace

網路這份憾動力,言語實在很難表達



發文: 183
積分: 4
於 2004-02-20 15:11 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
anthonychen wrote:
可以將圖檔存入MySQL中,資料型態是BLOB。
不過MySQL的BLOB大小有64K,如果有大圖檔需求可以使用MEDIUMBLOB or LONGBLOB。


BLOB ??
這種資料型態要怎麼以程式碼實作呢?
能不能提供個參考?


reply to postreply to post
不知不覺就2年
作者 Re:請問有辦法將照片(jpg.gif...)存入mysql嗎? [Re:x3711699]
sdargon





發文: 109
積分: 0
於 2004-02-20 16:40 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
版上有一些關於BLOB的討論

底下這篇是針對MySQL的
http://www.javaworld.com.tw/jute/post/view?bid=21&id=25730&tpg=1&ppg=1&sty=1&age=0

------------------------------------------------------------------
好像使用各家資料庫BLOB的方法都不太一樣說...
那這樣子是不是儘量不要用BLOB比較好呢@@a


reply to postreply to post
作者 Re:請問有辦法將照片(jpg.gif...)存入mysql嗎? [Re:sdargon]
marace

網路這份憾動力,言語實在很難表達



發文: 183
積分: 4
於 2004-02-20 16:53 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
看到了
感謝!!
不過感覺不是那麼方便 Black Eye


reply to postreply to post
不知不覺就2年
作者 Re:請問有辦法將照片(jpg.gif...)存入mysql嗎? [Re:x3711699]
eddie





發文: 19
積分: 0
於 2004-02-26 16:04 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
還有一個做法
先將圖檔資料讀入再轉成BASE64的格式
再存入MYSQL的TEXT的欄位屬性就可以了

從MYSQL讀出時再把BASE64轉回來

這是在PHP中的做法
因為PHP對DB沒有二進位的讀寫方法


reply to postreply to post
作者 Re:請問有辦法將照片(jpg.gif...)存入mysql嗎? [Re:x3711699]
shihhao





發文: 3
積分: 1
於 2004-03-16 09:37 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
不只圖片可以存到blob,word及excel都可以存到blob
可是在讀取的時後要判斷是哪種類型的檔案在用不同的方法讀取,
我同事有在網路找到讀取的方法喔


reply to postreply to post
作者 Re:請問有辦法將照片(jpg.gif...)存入mysql嗎? [Re:shihhao]
anthonychen

外線交給我

版主

發文: 2033
積分: 8
於 2004-03-16 10:22 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
shihhao wrote:
不只圖片可以存到blob,word及excel都可以存到blob
可是在讀取的時後要判斷是哪種類型的檔案在用不同的方法讀取,
我同事有在網路找到讀取的方法喔

可以分享一下這個讀取的方法給大家嗎?Blush


reply to postreply to post
作者 Re:請問有辦法將照片(jpg.gif...)存入mysql嗎? [Re:x3711699]
shihhao





發文: 3
積分: 1
於 2004-03-23 15:06 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
以下是在讀取mysql blob資料庫欄位的方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<%@ page contentType="text/html; charset=Big5" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import = "com.database.*"%>
<%
//Clear output buffer
response.reset();
 
//Get id seed
String id = request.getParameter("id");
 
if(id!=null){
 
  if(!id.equals("")){
    //Get image source from DB
    UploadFile Photo   = new UploadFile();
    Blob  picture = Photo.View(id);
 
    if(picture!=null){
      //Set content type
      //response.setContentType("application/msword");
      //response.setContentType("application/msexcel");
      //response.setContentType("application/pdf");
      response.setContentType("image/jpeg");
    
      //Blob to change into Byte
      InputStream is = picture.getBinaryStream();
      int length = (int) picture.length();
      byte[] buffer = new byte[length];
      is.read(buffer);
      is.close();
      
      //Response image stream
      ServletOutputStream sos = response.getOutputStream();
      sos.write(buffer);
      sos.flush();
      sos.close();
    }
  }
}
%>

抱歉,第一次post程式碼,不知道這樣可以不可以


anthonychen edited on 2004-03-23 15:17
reply to postreply to post
作者 Re:請問有辦法將照片(jpg.gif...)存入mysql嗎? [Re:x3711699]
cory

好可愛^_^



發文: 100
積分: 0
於 2004-08-02 13:23 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
找過全文檢索 沒有找到關於將圖片存入MySql
並將圖片從MySql 取出的相關範例n
如果有誰知道的話 煩請提供一下相關的資訊 感謝 Smile


reply to postreply to post
作者 Re:請問有辦法將照片(jpg.gif...)存入mysql嗎? [Re:cory]
alin





發文: 223
積分: 3
於 2004-08-02 13:42 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
MySql BLOB 的大小應該可以設定吧?

上次去看 CodeLib的網頁, 裡面有介紹到, 怎麼把 BLOB的大小改變

主要應該是改 my.ini 裡面的設定吧

在 [mysqld] 新稱***行
set-variable=key_buffer=16M
max_allowed_packet=16M

應該是這樣, 如果又錯 請多多指教囉 Smile


reply to postreply to post
作者 Re:請問有辦法將照片(jpg.gif...)存入mysql嗎? [Re:x3711699]
Always





發文: 1
積分: 0
於 2004-09-27 00:21 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請問如果要直接用mysql語法,將圖檔匯入,也是用insert指令嗎?可否給一句範例參考,感激。^_^

reply to postreply to post
作者 Re:請問有辦法將照片(jpg.gif...)存入mysql嗎? [Re:marace]
caterpillar

良葛格

版主

發文: 2613
積分: 70
於 2005-07-26 12:27 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
marace wrote:
BLOB ??
這種資料型態要怎麼以程式碼實作呢?
能不能提供個參考?


將檔案存入資料庫。。。
http://caterpillar.onlyfun.net/Gossip/JavaGossip-V2/BLOBAndCLOB.htm

還有Hibernate的。。。Big Smile
http://caterpillar.onlyfun.net/Gossip/HibernateGossip/BlobClob.html


reply to postreply to post
良葛格學習筆記
作者 Re:請問有辦法將照片(jpg.gif...)存入mysql嗎? [Re:caterpillar]
ben19770209





發文: 78
積分: 0
於 2005-10-21 18:17 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
caterpillar wrote:
將檔案存入資料庫。。。
http://caterpillar.onlyfun.net/Gossip/JavaGossip-V2/BLOBAndCLOB.htm

還有Hibernate的。。。Big Smile
http://caterpillar.onlyfun.net/Gossip/HibernateGossip/BlobClob.html


所以,若是在 hibernate 3 + oracle db 8i 要將一張圖檔寫入 blob 資料庫欄位的話
是不是一定要自定一個 hibernate 資料型態,來作 blob 與 byte[] 的轉換呢?


reply to postreply to post
作者 Re:請問有辦法將照片(jpg.gif...)存入mysql嗎? [Re:alin]
evali





發文: 27
積分: 0
於 2006-04-20 01:56 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請問…我設定了my.ini中的
set-variable=key_buffer=16M
set-vaiable=max_allowed_packet=16M
在my.ini看起來是設定成這樣…
但是我用mysqladmin看variable時…max_allowed_packet並未如期的更改…
請問是否有其他的更改方式??Sleepy



evali edited on 2006-04-20 12:52
reply to postreply to post
» JWorld@TW »  JDBC/SQL討論區 » MySQL

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8