I don't know where I have make a mistake in this program. I am not able to store the image retrived from database.
我不知道我在这个程序中犯了什么错误。我无法存储从数据库中恢复的图像。
import java.io.*;
import java.sql.*;
public class kmpp
{
public static void main(String args[]) throws IOException
{
FileOutputStream fos=null;
Connection con=null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","rock");
PreparedStatement ps=con.prepareStatement("select * from image where name=?");
ps.setString(1,"mohit");
ResultSet rs=ps.executeQuery();
if(rs.next())
{
InputStream is=rs.getBinaryStream(2);
fos=new FileOutputStream("F:/Documents and Settings/cboy/Desktop/New Folder/moh.jpg");
int data;
while((data=is.read())!=-1)
{
fos.write(data);
}
fos.close();
}
}
//is.close();
catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception caught ");
}
//fos.close();
//con.close();
}
}
1 个解决方案
#1
0
The second column is blob or longraw? If it's blob try to use rs.getBlob(2).getBinaryStream() instead of rs.getBinaryStream(2).
第二列是blob还是longraw?如果它是blob尝试使用rs.getBlob(2).getBinaryStream()而不是rs.getBinaryStream(2)。
#1
0
The second column is blob or longraw? If it's blob try to use rs.getBlob(2).getBinaryStream() instead of rs.getBinaryStream(2).
第二列是blob还是longraw?如果它是blob尝试使用rs.getBlob(2).getBinaryStream()而不是rs.getBinaryStream(2)。