应该是sql脚本使用不当,你的sql是什么?
解决方案 »
- 如何在一个编辑框中,同时显示文字与图片?????
- 怎样设置光标选中一段文字?
- 急,用jdbc 写"嫺"字保存到informix7.3 db里变成了"?",db 字符集是zh_tw?
- 送《java手机程序设计入门》,求帮助!!
- J2EE军团<25744484>技术群
- 如何使用指定密匙DES加密数据?
- 大家给我讲讲Static吧
- 在java里怎么把一个int型里的值转换成一个string呀?
- 跳出if,直接运行下一个while循环怎么办?
- 可能从数据库得到三种格式的时间字符串,如何使用系统自带类统一格式化为yyyy-MM-dd HH:mm:ss格式的时间
- 百分求解决思路及方案
- [求助]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());
}
}
}