保存图片到数据库的方法是这样做的:
保存进去了,应该没有问题!
File imagefile1 = new File(image1);
FileInputStream fis1 = null;
try {
fis1 = new FileInputStream(imagefile1);
PreparedStatement ps = connection.prepareStatement("update eating_corp set image1=? where id=?");
ps.setDouble(2,id);
ps.setBinaryStream(1,fis1,(int)imagefile1.length());
ps.executeUpdate();
}
catch(FileNotFoundException fnfe) {}
finally {
try {
fis1.close();
}
catch(IOException ioe) {
System.err.println("File Closing error: " + ioe);
}
}
保存进去了,应该没有问题!
File imagefile1 = new File(image1);
FileInputStream fis1 = null;
try {
fis1 = new FileInputStream(imagefile1);
PreparedStatement ps = connection.prepareStatement("update eating_corp set image1=? where id=?");
ps.setDouble(2,id);
ps.setBinaryStream(1,fis1,(int)imagefile1.length());
ps.executeUpdate();
}
catch(FileNotFoundException fnfe) {}
finally {
try {
fis1.close();
}
catch(IOException ioe) {
System.err.println("File Closing error: " + ioe);
}
}
解决方案 »
- 进来看看到底你java处于一个什么样的水平把。
- 完全解耦什么意思啊?
- 同样的程序在WINDOWS上和LINUX上差别那么大?
- 关于键盘事件的问题
- 我要实现一个简单功能
- 请教:关于Arrays类的sort()方法,和arraycopy()方法,还有求导数的算法
- JAVA中从键盘键入数据的代码怎么写?
- java程序运行时出现了空指针类错误,请高手指教;初来乍到,程序有很多地方有待改进,大家莫笑哈
- 很多组件的构造函数中有int型参数,可很多时候用RIGHT之类的,是宏吗?
- InetAddress.getByName抛出异常的问题
- 看不懂程序
- 请问各位前辈哪里有JBuilder4.0(市场上有卖的吗),俺这里没有卖4.0的,只有3.5
能帮我试试看看吗,怎么不行,
你写的那个程序有完整的版本吗,能不能给我看看。
带oracle数据库表的。
[email protected]
7173705655970504-10500-1-1-1000666666-61-61-71-125-1259011111177-58-58-76646444-1-1-1-61-61-71-91-91-99-27-27-31107107101000-121121-121114103114-55-61-55676067-1-1-1-50-62-72-81-92-100-22-27-31113106101000-108-108-108-83-83-83333333-67-67-67-34-34-34-10-100-1999999-50-62-72477979115115115-100-1-100-100-1-1105105105-66-66-66-45-45-45636363-64-64-64-1030102-1-1-520-128-128-12800-128-1280-128-128-128102102-5251511020-1280-103-103-166-102-89343434-11025100-12805560-1102-52511020-103-103-103252525-77-77-77-27-27-31107107101102102-103102102102-52-52-52-58-43-30-117-103-7512712712776767600000630012700-6500-1063006363063127063-65063-10127001276301271270127-650127-10-6500-65630-651270-65-650-65-10-100-1630-11270-1-650-1-1630063063630127630-65630-16363063636363631276363-656363-163127063127636312712763127-6563127-163-65063-656363-6512763-65-6563-65-163-1063-16363-112763-1-6563-1-11270012706312701271270-651270-112763012763631276312712763-6512763-1127127012712763127127127127127-65127127-1127-650127-6563127-65127127-65-65127-65-1127-10127-163127-1127127-1-65127-1-1-6500-65063-650127-650-65-650-1-65630-656363-6563127-6563-65-6563-1-651270-6512763-65127127-65127-65-65127-1-65-650-65-6563-65-65127-65-65-65-65-65-1-65-10-65-163-65-1127-65-1-65-65-1-1-100-1063-10127-10-65-10-1-1630-16363-163127-163-65-163-1-11270-112763-1127127-1127-65-1127-1-1-650-1-6563-1-65127-1-65-65-1-65-1-1-10-1-163-1-1127-1-1-65-1-1-11270-1-1050-1-810-1-570-1-330-1-90-1-10-17-10-41-10-65-10-89-10-113-10119-1095-1071-1047-1023000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000440000-1050-60078-40-11792872-80-96-63-1258194292-56-80-95-61-121163338-10372-79-94-59-1172451106-36-561799-60-1133267187634-78-92-55-1263679-8692414837-53-1051493-62-10041-111-9077-12450111-2260-10411539-513677-12654-1573-7688-49-9444-1271069-70-1340-45-10974-12562-67-23116-86-56-8867-83-50-84-86-1135-42-8248-71-126125-8117-2074-7910225-1067710718-8381-11838386-99-5319-2890-7487-43-114108-8723103-50-119118-123102-59-10187-9583-711131-135310680113-30-60110-1718-10-70-16-1698-105-120-113-110-60-52-72-77-25-124-11039-4152-116-1311499-53-100174754448811672-79-10659-9116-116-110-81106-11710691-69-9076-70-82-20-58-97-29-38547786-9-18-47-67-119-85-229-3651103-25-71-10530711102446-15-73-49-125103-577627-76-15-23-413-3578151330116-7-54-33-49-10187-1135161123-32-1727-69-11347-100-2-56-7-10-593139-97-33-2125-23-2-19117-4896-32-1571-97834-114-121-33-127837-72-33-126-1533-88-98-12717545633-124-177312030-1232590-7233-122-201058830-121331225634-12019102-44687144-74-24-947040-5839-40-11652-42104-29-11556-26-88-93-125114-76-29-1136469100-1131310105-28-11170185732-1107654121-93-11011-158101-1138278-2395-10786-46-121101-106-17109-55-91122941268994-104987871102-103-69-99-119-90104106-827388-101110-785103-100102-51733988118-34-8785-9812278-59103-9776-3910481-12614-2283-95-122-22-124104-945445-54-2476-11462106-105-1184786106-23-91-104102-86105119-51920-87-92-55-43103-48-89-96-10686-37-128-911853-101-119118-4-119269469100-2371298561-44-38-611065-1541-85-128-72-82-9-109-86-74-34-38105498590-41-11098-42113-10590118-5057-7489-78-5050-7425-82-58-665310888-63-10-22-93-87-52117-69-10092-739-828-78-85-127123-84-75-3394-74-21107-3914-21-27114-94-901129118-479439-17-72-10-10611-84-83-381221090-78-16121-85111-89-72-51-117-81114-572-36-1786-19-118120106-73-1514124-16-6117279295-7215-8110787-61-84-14122-17-593295-25-79-603351-9-79-756237-6349-8612677-117-3599-51110-73-80-79-37-431075010035-71-36-44-54-93-90-10250-49-71-6-6851-65-9873-27-81-89-92-90-8650-4746-755484-11666-1095-12-10981-65-76116-83-728293-1189641975-29-42861199335-4073-119-353-394293451087951-94-5153-45-9366-19-74979335-99-4116-44106-911-32-3637-27-1946-33105-4112552100-10122-50-111127126-9385-83107-11711140120-50331061286-30-95-10624-30-29407140-7185-108115123-32-35-40-62-51-45-26102774122-39-9474481-63-123-6770-20-120-11310776-70-2294-19-51120-20-836-84-84112-5611490-100-47-5-31-5091-581899-4-102-36831177812376579124-14-15-7479-9060-59100-107-9044-7134-41306197-45-135843-17-82-11012421-14791173112676-6690-1001256836784660-5-84107103-77-71-483127123-22-44127-666194-26472834-776-23-33-7546-7663-748112118-91332821472-92-10117-123-12794-87-42-86-86-8961-5-1196-126-449786-18-40-89-64-949616125-8912286-681043-83117578043311215124-80-960120-3-50-126-46123318-5921-78-119-99476029-3623-4-42-122-75-85930-84121-53-61971-45-110-62-66-481697-7-1099314127-12263-17-51-80897220-400-6751-60-46-55488636-52-36-181121184614861134476896-612611466-509778-1164010891-16-1028-71397-27116109-63-362093-77-94-77-1970-12848-37-482797-56615738-8464-90-77-2929-3-24-87-114-84-56112-102-46-3832-39883639575073112-1241033125-12-5674149118-11676-1203755-119-939775087-100121013681-736752-114-1475120-116-5641-71-10874-120-845075-83124-5643-832075-121-5211474-75108-5645-95-10875-122-208273-67-11618-3226-137395-26-5211912043-9048-69-12076-9758333-125-23-99-37-98-87-55-45-52-115-10229107-90-48-80-55-7860-94-115-1016127-2672-108977-108-96-4777-32129027-8973-50106-12681-123-211-4965959-5857120-5081-12110791-55471213951-72-484490-3812923863-7879102-11811194-7811397-2474-87-49-46-1077694-22-69-2585-26-71368112649-9416117-9878-4673-112-126981169631-91-4364858958-1169715-9516-3969-6157-71-52-95-117-1039168-887471-22-5499-98197728-352276-39738389-6244-96-96-54-23-32-68954-95-66110-99-3392-8758-1199084-9111884-100-29-20-8745-51-5555-93388-88-91-7842-29-4-92388-7-11811690-67-9617-87-11-43-665785-8996-848776-11539481275811-96-12157-2180818867-11049-85-12321591058425-8618-113-6809136-12106727-69-41124-10-43-9423-3107115-78-880-112106-108-10482-99-481014383-68308451114539693-437-81-37100-76-79-112-274346-43-5469-24-601548-12115123-85-526610788-88-12245-78-82-107261089927-98-52-46-4240-74-91-8381111-6991-35-2654-74-675-18111932792-301423-86-5969-18113-59-103566858-9-71-48-11511069-3869-1129689-9-70-40-51-82118-73-53-35-18122-9-69-3213471201334-34-14-102-9-68-2477-81122-8375-34-11-70-9-67-16-115-17119-3743-33-6-38-9-66-24-67-197822059
怎么回事呀?
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="eating_corp.*" %>
<%@ page contentType="text/html;charset=gb2312" %>
<html>
<body>
<img src="/eating_corp/showimage.jsp?id=23.0" width="500" height="60">
</body>
</html>
显示不出来
而且我一开始用WEBLOGIC5.1,不能保存图片到数据库里,后来只用RESIN就可以了。为什么?
<%@ page language="java" import="java.io.*,java.util.*,java.sql.*" %>
<%
String image_id=(String)request.getParameter("id");
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:qyjy";
String username="sa";
String password="";
/*
String driver = "weblogic.jdbc.mssqlserver4.Driver";
String url = "jdbc:weblogic:mssqlserver4:qyjy@pc_server";
String username="sa";
String password="";
*/
if(image_id!=null)
{
try{
Class.forName(driver);
Connection con=DriverManager.getConnection(url,username,password);
/*
java.util.Properties props = new java.util.Properties();
props.put("weblogic.codeset","GBK");
props.put("user",username);
props.put("password",password);
Driver myDriver = (Driver)Class.forName("weblogic.jdbc.mssqlserver4.Driver").newInstance();
Connection con = myDriver.connect(url,props);
*/
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from eating_corp where id = "+image_id);
if(rs.next())
{
String dim_image ;
String corp_no;
//System.out.println(rs.getString("corp_no"));
//System.out.println("45445");
//System.out.println(image_id);
byte[] blocco = rs.getBytes("image1");
System.out.println(blocco.length);
response.setContentType("image/jpeg");
ServletOutputStream op = response.getOutputStream();
op.write(blocco);
}
rs.close();
stmt.close();
con.close();
}
catch(Exception e){
out.println("An error occurs:"+e.toString());
}
}
%>
我改了一下,op.write(bloboo);
showimage.jsp?id=23显示出来,看不到数字了,点右键的属性,也是JPEG类型了。
但是,图片显示是一个叉,还是出不来!
2。oracle用blob存储图片格式。
3.写sql, insert into table (id,blob_pct) value(123,EMPTY_BLOB()) ; 然后select blob_pct from table where id=123;
oracle.sql.BLOB blob = rs.getBlob("blob_pct");
try{
OutputStream outstream = blob.getBinaryOutputStream();
Vector v = rAttachment;
byte[] bAtt = null;
for(int i=0;i<v.size();i++)
{
bAtt = (byte[])v.elementAt(i);
outstream.write(bAtt,0,bAtt.length);
}
outstream.close();
rs.UpdateBlob("blob_pct",blob);
...
DataOutputStream os = new DataOutputStream( response.getOutputStream() );
InputStrean input = blob.getBinaryStream();
while ((length = input.read(buffer)) !=-1)
{
os.write(buffer,0,length);
}
}
input.close();
os.close();
...
请问
oracle.sql.Blob的包在哪,怎么找不到》?
import oracle.jdbc.driver.*;
我查了一下,国外的几个JAVA方面的网站 ,也是这样说的,
www.java.sun.com的论坛上说:
First , you should know the file type or you have store the filename.
Second write a JSP or Servelt to handle BLOB, and get values as a byte array.
then set the content type
request.setContentType ("image/gif") ;// or jpeg, bmp ...
last, write byte array into output stream:
response.getOutputStream ().write (bytes) ;
response.getOutputStream ().close () ; 我也是三步:
1: byte[] blocco = rs.getBytes("image1");
2: response.setContentType("image/jpeg");
3: ServletOutputStream op = response.getOutputStream();
op.write(blocco);应该是对的呀,但是取出来了,就是显示不出来。!!!!!!!!!SIGH\!!是不是ORACLE和SQLSERVER不一样?
你有没有试过SQLSERVER下。行不行?