怎样把一幅图像存到数据库里面去,然后读出来显示? jspsmartupload组建上传具体代码在jspsmartupload得例子里就有,看看吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 GOOGLE 上搜呀大把这样的例子。 建议你不要把图片存到数据库存个url就可以了吧 oracle数据库,各位兄弟有没有好网址介绍一下,让我看看相关文章阿或者列出个程序DEMO阿,谢谢! oracle有一种字段类型BLOB,可以存储图象,使用时需要以流的形式写入和读出,具体代码手头没有 ////////////////////////////////////////////////////////////插入文件import java.sql.*;public class InsertFileTest{ String strDriverClass = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; String strUrl = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test"; String strUser = "sa"; String strPsw = ""; private Connection conn; public InsertFileTest() { try { //引入要SqlServer的Jdbc数据库驱动 Class.forName(strDriverClass).newInstance(); //连接数据 conn = DriverManager.getConnection(strUrl,strUser,strPsw); String filePath = "C:\\dict\\index_dict.xml"; java.io.File file = new java.io.File(filePath); java.io.FileInputStream ofis = new java.io.FileInputStream(filePath);// String sql = "BULK INSERT bigfile(id,myxml,mytext) FROM ('1','C:\\dict\\index_dict.xml','C:\\dict\\index_dict.xml'"; String sql = "SELECT TOP 0 code,myfile,size FROM filetest";// CallableStatement statement = conn.prepareCall(sql); Statement objStm = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); ResultSet ofRS = objStm.executeQuery(sql);// ofRS.insertRow(); ofRS.moveToInsertRow(); // ofRS.next(); ofRS.updateString("code","index"); ofRS.updateBinaryStream("myfile", ofis, (int)file.length()); ofRS.updateInt("size",(int)file.length()); //Clob clob = ofRS.getClob("myxml"); //byte[] buf = new byte[(int)file.length()]; //java.io.FileOutputStream fos = new java.io.FileOutputStream(file); //fos.write(buf); //clob.getAsciiStream().read(buf); //ofRS.updateClob("myxml",clob); ofRS.insertRow(); ofRS.close(); objStm.close(); conn.close(); } catch(Exception ex) { ex.printStackTrace(); } } public static void main(String[] args) { new InsertFileTest(); }}////////////////////////////////////////////////////////////////读取文件import java.sql.*;import java.io.*;public class ReadFile{ public ReadFile() { } public static void main(String[] args) { String strDriverClass = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; String strUrl = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test"; String strUser = "sa"; String strPsw = ""; Connection conn; try { //引入要SqlServer的Jdbc数据库驱动 Class.forName(strDriverClass).newInstance(); //连接数据 conn = DriverManager.getConnection(strUrl,strUser,strPsw); String filePath = "C:\\dict\\index_dict_temp.xml"; java.io.File file = new java.io.File(filePath); if(!file.exists()) {// String sql = "BULK INSERT bigfile(id,myxml,mytext) FROM ('1','C:\\dict\\index_dict.xml','C:\\dict\\index_dict.xml'"; String sql = "SELECT code, myfile,size FROM filetest WHERE code='index'";// CallableStatement statement = conn.prepareCall(sql); Statement objStm = conn.createStatement(); ResultSet ofRS = objStm.executeQuery(sql); String code = null; int size = 0; if(ofRS.next()) { code = ofRS.getString("code"); size = ofRS.getInt("size"); System.out.println(code+" "+size); } ofRS = objStm.executeQuery(sql); if(ofRS.next()) { java.io.InputStream is = ofRS.getBinaryStream("myfile"); byte[] buf = new byte[size]; is.read(buf); FileOutputStream fos = new java.io.FileOutputStream(filePath); fos.write(buf); System.out.println(new String(buf)); } ofRS.close(); objStm.close(); conn.close(); } } catch(Exception ex) { ex.printStackTrace(); } }} http://www.csdn.net/Develop/article/20%5C20484.shtm这里有一篇文章(不是我写的),大概对你有所帮助 在GridBagLayout布局下如何调整按钮的大小???? java io流读取文件 关于 createNewFile 新手问题1 字符串输出 读取文件编码格式为GBK数据的问题 借人气问问题 Java 的自定义事件 初学java求助 static final有点疑惑,大神帮忙解答下 救急:有关 Log4J 系统的文件属性配置的问题? ==JLable中add另一个JLabel==
大把这样的例子。
或者列出个程序DEMO阿,谢谢!
//插入文件
import java.sql.*;public class InsertFileTest
{
String strDriverClass = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String strUrl = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
String strUser = "sa";
String strPsw = ""; private Connection conn; public InsertFileTest()
{
try
{ //引入要SqlServer的Jdbc数据库驱动
Class.forName(strDriverClass).newInstance();
//连接数据 conn = DriverManager.getConnection(strUrl,strUser,strPsw);
String filePath = "C:\\dict\\index_dict.xml";
java.io.File file = new java.io.File(filePath);
java.io.FileInputStream ofis = new java.io.FileInputStream(filePath);// String sql = "BULK INSERT bigfile(id,myxml,mytext) FROM ('1','C:\\dict\\index_dict.xml','C:\\dict\\index_dict.xml'";
String sql = "SELECT TOP 0 code,myfile,size FROM filetest";
// CallableStatement statement = conn.prepareCall(sql); Statement objStm = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); ResultSet ofRS = objStm.executeQuery(sql);
// ofRS.insertRow();
ofRS.moveToInsertRow();
// ofRS.next();
ofRS.updateString("code","index");
ofRS.updateBinaryStream("myfile", ofis, (int)file.length());
ofRS.updateInt("size",(int)file.length());
//Clob clob = ofRS.getClob("myxml");
//byte[] buf = new byte[(int)file.length()];
//java.io.FileOutputStream fos = new java.io.FileOutputStream(file);
//fos.write(buf);
//clob.getAsciiStream().read(buf); //ofRS.updateClob("myxml",clob); ofRS.insertRow();
ofRS.close();
objStm.close();
conn.close();
}
catch(Exception ex)
{
ex.printStackTrace();
}
} public static void main(String[] args)
{
new InsertFileTest();
}
}//////////////////////////////////////////////////////////////
//读取文件
import java.sql.*;
import java.io.*;public class ReadFile
{ public ReadFile()
{
} public static void main(String[] args)
{
String strDriverClass = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String strUrl = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
String strUser = "sa";
String strPsw = "";
Connection conn;
try
{ //引入要SqlServer的Jdbc数据库驱动
Class.forName(strDriverClass).newInstance();
//连接数据
conn = DriverManager.getConnection(strUrl,strUser,strPsw);
String filePath = "C:\\dict\\index_dict_temp.xml";
java.io.File file = new java.io.File(filePath); if(!file.exists())
{
// String sql = "BULK INSERT bigfile(id,myxml,mytext) FROM ('1','C:\\dict\\index_dict.xml','C:\\dict\\index_dict.xml'";
String sql = "SELECT code, myfile,size FROM filetest WHERE code='index'";
// CallableStatement statement = conn.prepareCall(sql); Statement objStm = conn.createStatement(); ResultSet ofRS = objStm.executeQuery(sql);
String code = null;
int size = 0;
if(ofRS.next()) {
code = ofRS.getString("code");
size = ofRS.getInt("size");
System.out.println(code+" "+size);
} ofRS = objStm.executeQuery(sql);
if(ofRS.next())
{
java.io.InputStream is = ofRS.getBinaryStream("myfile");
byte[] buf = new byte[size];
is.read(buf); FileOutputStream fos = new java.io.FileOutputStream(filePath);
fos.write(buf); System.out.println(new String(buf));
} ofRS.close();
objStm.close();
conn.close();
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
这里有一篇文章(不是我写的),大概对你有所帮助