java´æ´¢Í¼Æ¬µ½Êý¾Ý¿â
1 mysql´æ´¢´óÈÝÁ¿µÄ¶þ½øÖÆÎļþµÄ¸ñʽÊÇblob£¬Æäʵ³ýÁËͼƬ»¹¿ÉÒÔ´æ±ðµÄ
2 ÒªÏòÊý¾Ý¿â´æ´¢¶þ½øÖƵÄÎļþÒ»¶¨Òª°ÑÒª´æ´¢µÄÊý¾Ýת»»³É¶þ½øÖÆÁ÷
·Ï»°¾Í²»¶à˵ÁË£¬´ó¼Ò¿´¿´´úÂëºÜÈÝÒ×Ã÷°×£¬ÏÈÀ´¿´Ò»¸öapp³ÌÐò£¬µ±È»Ê×ÏÈÄúÒªÔÚÊý¾Ý¿âÖÐÏȽ¨Á¢Ò»¸öÓÃÓÚ±£´æÍ¼Æ¬µÄ±íºÍÏàÓ¦µÄÁУ¬Êý¾Ý¸ñʽΪblob
package com.lizhe;
import java.io.*;
import java.sql.*;
public class PutImg {
public void putimg() {
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url = "jdbc:mysql://localhost/img?user=root&password=root&useUnicode=true&characterEncoding=gbk";
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
//stmt.execute("insert into imgt (id) values (5)");
stmt.close();
PreparedStatement pstmt = null;
String sql = "";
File file = new File("c:\\blog.jpg");
InputStream photoStream = new FileInputStream(file);
//sql = " UPDATE imgt SET img = ? ";
sql = "INSERT INTO imgtable (img) VALUES (?)";
pstmt = conn.prepareStatement(sql);
pstmt.setBinaryStream(1, photoStream, (int) file.length());
pstmt.executeUpdate();
pstmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]){
PutImg pi=new PutImg();
pi.putimg();
}
}
InputStream photoStream = new FileInputStream(file);
¿ÉÒÔºÜÇå³þµÄ¿´µ½ÎÒÃÇÊ×ÏȰÑÒ»¸öͼƬÎļþ(µ±È»Ò²¿ÉÒÔÊDZðµÄʲôÎļþ)ת»»³ÉÁËÒ»¸ö¶þ½øÖÆÊäÈëÁ÷
pstmt.setBinaryStream(1, photoStream, (int) file.length());
Õâ¸ö·½·¨½¨Òé´ó¼ÒÈ¥²éÒ»ÏÂAPIÎĵµ,µÚÒ»¸ö²ÎÊýÊÇͨÅä·ûλÖÃûµÄ˵,µÚ¶þ¸ö²ÎÊýÊÇÁ÷,ÕâºÍÒÔÍùµÄstringÀàÐ͵IJÎÊý²»Ì«Ò»Ñù,ÎÒ¸Õ¿´µ½µÄÊ
Ïà¹ØÎĵµ£º
½«×Ö´® String ת»»³ÉÊý×ÖÀàÐÍ
String ת int
1.) int i = Integer.parseInt([String]); »ò i = Integer.parseInt([String],[int radix]);
2.) int i = Integer.valueOf(my_str).intValue();
String ת Float
Float f = Integer.valueOf(my_str).floatValue();
String ת float
float f=new Float(my+str).floa ......
Ðí¶àʱºòÎÒÃÇÐèÒªÓõ½Ïß³Ì ±ÈÈçÏ£ÍûÒ»¸ö¸½¼ÓµÄ¹¦ÄÜ ²»ÒªÓ°ÏìÕû¸öÁ÷³ÌµÄ¹¦ÄÜ£¬±ÈÈçij¸öÁ÷³ÌÐèÒª¼ÓÈëÈÕÖ¾£¬µ«ÊDz»Ï£Íû¼Ç¼ÈÕÖ¾µÄ¹¦ÄÜÓ°ÏìÕû¸öÁ÷³ÌµÄÐÔÄÜ£¬²»ÄÜÒòΪ¼Ç¼ÈÕÖ¾°ÑÕû¸öÁ÷³Ì¸ø¿¨×¡ÁË¡£ÔÚÕâ¸öÖÖÇé¿öÏ£¬ÎÒÃÇÐèҪʹÓÃÏ̡߳£ÈüǼÈÕÖ¾ÔÚµ¥¶ÀÒ»¸öÏß³ÌÀïÃæÅÜ£¬¾Í²»»áÓ°Ïì¶¼ÆäËûÁ÷³ÌÁË¡£
  ......
̸̸Java¼Ì³ÐÖеÄÖØÔØ£¬¸²¸ÇºÍÒþ²Ø
ºÃ¾Ã²»Ð´²©¿ÍÁË£¬¾àÀëÉÏһƪÒѾ¹ýÁËÁ½Äê¶àÁË¡£ÕâÁ½ÄêÔÚ¸ÉÂï,×ÜÖ®Ò»ÄêÄѾ¡£¡
ǰһ¶Îʱ¼äæÁËÁ½¸öÔ£¬Ã¦×ÅÑо¿ºÍ×öһЩSSH¼Ü¹¹µÄ¶«Î÷£¬Á½¸öÔÂÏÂÀ´£¬ÊÕ»ñÆÄ·á£¬×î½üÏÐÏÂÀ´ÁË£¬ÓÚÊǾÍÍ´¿ìµÄ¿ªÊ¼ÍæÓÎÏ·£¬µ«ÊDz»ÖªÔõôµØ£¬ÔõÃ´Íæ¶¼Ã»Òâ˼£¬ÓÚÊǾö¶¨¿ªÊ¼ÔٺúÃÑо¿Ñо¿Java°É¡£ÓÚÊÇ´ó¸Å·ÁË· ......