sqlserver数据库如何储存音乐文件和图片 问题入题 我的领悟能力不佳,请说详细,最好能来段代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 05用varbinary(max)\nvarchar(max)等2000用Image\text\ntext 如果为了性能,一般会选择存文件url地址,文件存放于磁盘中如果为了文件的安全性,那可以存放在ntext,image字段中写入文件需要程序读二进制来处理,具体你可以上百度google一下 吧你的数据转换成 二进数据 05用Image\varbinary(max)等 2000用Image\text\ntext 一般的思想是存储地址,然后在WEB中html中写入相应的标签即可! 用java写的:public class 数据库存图片 { private Connection con = null; public 数据库存图片() throws SQLException, ClassNotFoundException { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); con = DriverManager .getConnection( "jdbc:sqlserver://127.0.0.1;databasename=?", "sa", ""); } private void savaPiture() throws SQLException, ClassNotFoundException, FileNotFoundException { String picn = "C:\\Documents and Settings\\Administrator\\My Documents\\My Pictures\\IMG0008A.jpg"; File file = new File(picn); long filelong = file.length(); int flong = (int) filelong; FileInputStream fis = new FileInputStream(file); String sqli = "insert into PICTURE values(?)"; PreparedStatement ps = con.prepareStatement(sqli); ps.setBinaryStream(1, fis, flong); ps.execute(); } private void readPicture() throws SQLException, ClassNotFoundException, IOException { String sqlimg = "select image from PICTURE"; PreparedStatement psi = con.prepareStatement(sqlimg); ResultSet rsi = psi.executeQuery(); if (rsi.next()) { System.out.println("进入if"); String path = "main.jpg"; File file = new File(path); FileOutputStream sout = new FileOutputStream(file); InputStream in = rsi.getBinaryStream(1); byte b[] = new byte[1024]; int i = in.read(b); while (i > -1) { System.out.println("进入循环"); sout.write(b, 0, i); i = in.read(b); } sout.flush(); sout.close(); } } public static void main(String[] args) throws SQLException, ClassNotFoundException, IOException { new 数据库存图片().readPicture();//取图片 //new 数据库存图片().savaPiture();//存图片 }} 如果是放数据库里,则一般是转换为二进制,然后保存到类型为image的字段中,取出来时再转换。否则只保存文件的路径,文件保存再硬盘里 Sql 2000 行列转换的问题 导数据库的数据的问题 请教一个Sql语句 是否有时时的access同步到sqlserver的方法(求高手) 适合各种考试题型的数据库表设计方案! 快下班了 紧急提问 请高手帮写个SQL 远程连接SQL Server2005数据库 交叉报表求教(难) SqlServer中的数据库中的dtpro...怎么是用户表 一个一直没有找原因的问题? 存储过程中参数如何放到execute中执行?
2000用Image\text\ntext
如果为了文件的安全性,那可以存放在ntext,image字段中
写入文件需要程序读二进制来处理,具体你可以上百度google一下
05用Image\varbinary(max)等
2000用Image\text\ntext
private Connection con = null; public 数据库存图片() throws SQLException, ClassNotFoundException {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager
.getConnection(
"jdbc:sqlserver://127.0.0.1;databasename=?",
"sa", "");
} private void savaPiture() throws SQLException, ClassNotFoundException,
FileNotFoundException {
String picn = "C:\\Documents and Settings\\Administrator\\My Documents\\My Pictures\\IMG0008A.jpg";
File file = new File(picn);
long filelong = file.length();
int flong = (int) filelong;
FileInputStream fis = new FileInputStream(file);
String sqli = "insert into PICTURE values(?)";
PreparedStatement ps = con.prepareStatement(sqli);
ps.setBinaryStream(1, fis, flong);
ps.execute();
} private void readPicture() throws SQLException, ClassNotFoundException,
IOException { String sqlimg = "select image from PICTURE";
PreparedStatement psi = con.prepareStatement(sqlimg);
ResultSet rsi = psi.executeQuery();
if (rsi.next()) {
System.out.println("进入if");
String path = "main.jpg";
File file = new File(path);
FileOutputStream sout = new FileOutputStream(file);
InputStream in = rsi.getBinaryStream(1);
byte b[] = new byte[1024];
int i = in.read(b);
while (i > -1) {
System.out.println("进入循环");
sout.write(b, 0, i);
i = in.read(b);
}
sout.flush();
sout.close();
}
} public static void main(String[] args) throws SQLException,
ClassNotFoundException, IOException {
new 数据库存图片().readPicture();//取图片
//new 数据库存图片().savaPiture();//存图片
}
}
否则只保存文件的路径,文件保存再硬盘里