【Java开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了Java开源代码-BlobShow.java的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
import java.
sql.*;
import javax.swing.*;
public class BlobShow
{
public static void main(String[] args)
{
Connection conn=null;
Statement st=null;
ResultSet rs=null;
Blob blob=null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(ClassNotFoundException ea)
{
ea.printStackTrace();
}
try
{
String url="jdbc:oracle:thin:@localhost:1521:yuanyuan";
conn=DriverManager.getConnection(url,"scott","tiger");
conn.setAutoCommit(false);
st=conn.createStatement();
rs=st.executeQuery("select * from myblob where id=1");
if(rs.next())
{
blob=rs.getBlob("fblob");
ImageIcon icon=new ImageIcon(blob.getBytes(1,(int)blob.length()));
JLabel l=new JLabel(icon);
JFrame jf=new JFrame("mywife");
jf.getContentPane().add(l);
jf.pack();
jf.setVisible(true);
}
}
catch(SQLException se)
{
se.printStackTrace();
}
finally
{
//---finally--start
if(rs!=null)
{
try
{
rs.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
//////////////////////////////
if(st!=null)
{
try
{
st.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
/////////////////////////////
if(conn!=null)
{
try
{
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
}
}