如何在mysql储存二进制图片(java,jsp) 应该是sql脚本使用不当,你的sql是什么? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 贴出你的sql你可以先在mysql里运行一下你的sql语句~ 首先你要确定你的SQL是对的,还有你要有权限,没有权限也可能出现上面的错误。没看到你的邮箱呀,我可以发一个把相版从数据库中读,写到数据库中去的例子给你! 将SQL语句贴来看看,应该是SQL的错误,先将SQL语句独立运行看看。 四个本问题的贴子至今没有任何人可以回答,全部都是可以啊,行啊,没问题啊没有任何代码证明我的信箱是 [email protected]收到可行代码立刻结贴送分http://community.csdn.net/Expert/topic/3638/3638776.xml?temp=.6011927http://community.csdn.net/Expert/topic/3637/3637320.xml?temp=.0927698http://community.csdn.net/Expert/topic/3638/3638807.xml?temp=.9520227http://community.csdn.net/Expert/topic/3638/3638773.xml?temp=.4013636 插入/查询正常。的确可以,这是数据库一般的功能。try { Class.forName("org.gjt.mm.mysql.Driver").newInstance(); String url ="jdbc:mysql://localhost/test?user=root&password=root&useUnicode=true&characterEncoding=gbk"; Connection conn = DriverManager.getConnection(url); Statement stmt = conn.createStatement(); stmt.execute("insert into test(myid) values (5)"); stmt.close(); PreparedStatement pstmt = null; String sql = ""; File file = new File("c:\\kick.jpg"); InputStream photoStream = new FileInputStream(file); sql = " UPDATE test SET photo = ? WHERE myid = 5" ; pstmt = conn.prepareStatement(sql); pstmt.setBinaryStream(1, photoStream, (int)file.length()); pstmt.executeUpdate(); pstmt.close(); conn.close();} catch (Exception e) { e.printStackTrace();} 我用yahoo和sohu的发了过去。 将图片文件存入数据库的例子,请大家看一下:import java.sql.*;import java.io.*;class BlobTest { public static void main(String args[]){ try{ RandomAccessFile raf = new RandomAccessFile("DukeTest.bmp","rw"); DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@your_server:1521:your_sid","user","password"); PreparedStatement pstmt = conn.prepareStatement("INSERT INTO BlobTest valueS( ?, ? )" ); pstmt.setString( 1, "photo1"); File imageFile = new File("duke.gif"); InputStream is = new FileInputStream(imageFile); pstmt.setBinaryStream( 2, is, (int)(imageFile.length())); pstmt.executeUpdate(); pstmt = conn.prepareStatement("SELECT image FROM BlobTest WHERE name = ?"); pstmt.setString(1, "photo1"); ResultSet rs = pstmt.executeQuery(); if(rs.next()){ Blob blob = rs.getBlob(1); int length = (int)blob.length(); byte [] _blob = blob.getBytes(1, length); raf.write(_blob); } System.out.println("Completed..."); }catch(Exception e){ System.out.println(e.getMessage()); } }} 求助个进制转换的问题 如何准确统计页面上输入的一个字符串在DB2中所占的空间大小? 请问Tomcat产生的404错误页,要放在那个路径下? 有谁知道怎么保存JMStudio捕捉的视频和声音吗?(能看到和听到我好高兴,可惜测试了很久不知道如何保存) int/string JAVA有切除小数点后面的函数么(不是四舍五入),谢谢。 JB7+tomcat 开发Servlet 寻求帮助! 关于JBuilder的问题!!!! 我想用java 编个基于WEB的聊天室程序,可以给个算法吗? java 返回数组怎么写 百分求解决思路及方案 [求助]POI如何处理超级链接
你可以先在mysql里运行一下你的sql语句~
没有任何代码证明我的信箱是 [email protected]
收到可行代码立刻结贴送分
http://community.csdn.net/Expert/topic/3638/3638776.xml?temp=.6011927
http://community.csdn.net/Expert/topic/3637/3637320.xml?temp=.0927698
http://community.csdn.net/Expert/topic/3638/3638807.xml?temp=.9520227
http://community.csdn.net/Expert/topic/3638/3638773.xml?temp=.4013636
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/test?user=root&password=root&useUnicode=true&characterEncoding=gbk";
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
stmt.execute("insert into test(myid) values (5)");
stmt.close();
PreparedStatement pstmt = null;
String sql = "";
File file = new File("c:\\kick.jpg");
InputStream photoStream = new FileInputStream(file);
sql = " UPDATE test SET photo = ? WHERE myid = 5" ;
pstmt = conn.prepareStatement(sql);
pstmt.setBinaryStream(1, photoStream, (int)file.length());
pstmt.executeUpdate();
pstmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
import java.sql.*;
import java.io.*;
class BlobTest {
public static void main(String args[]){
try{
RandomAccessFile raf = new RandomAccessFile("DukeTest.bmp","rw");
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@your_server:1521:your_sid","user","password");
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO BlobTest valueS( ?, ? )" );
pstmt.setString( 1, "photo1");
File imageFile = new File("duke.gif");
InputStream is = new FileInputStream(imageFile);
pstmt.setBinaryStream( 2, is, (int)(imageFile.length()));
pstmt.executeUpdate();
pstmt = conn.prepareStatement("SELECT image FROM BlobTest WHERE name = ?");
pstmt.setString(1, "photo1");
ResultSet rs = pstmt.executeQuery();
if(rs.next()){
Blob blob = rs.getBlob(1);
int length = (int)blob.length();
byte [] _blob = blob.getBytes(1, length);
raf.write(_blob);
}
System.out.println("Completed...");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}