java 中图像保存到数据库 http://www.csdn.net/expert/topic/557/557668.xml?temp=.8389246这是JSP版上的一片相关的文章 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 别人的东西: Object source = e.getSource(); try { if (conn.isClosed()) conn = DriverManager.getConnection("jdbc:weblogic:mssqlserver4", props); } catch ( Exception ex ) { ex.printStackTrace(); } if ( source == App.frame.jButton1 ) { String StrSql = "insert into ServletDB values (?,?,?,?)"; try { File f = new File("c:\\1.png"); FileInputStream fin = new FileInputStream(f); PreparedStatement ps = conn.prepareStatement(StrSql); ps.setString(1,"李丽华"); ps.setInt(2,12); ps.setString(3,"RD"); int len = (int)f.length(); ps.setBinaryStream(4,fin,len); ps.executeUpdate(); ps.close(); fin.close(); } catch ( Exception ex ) { ex.printStackTrace(); } } else { try { FileOutputStream fou = new FileOutputStream("c:\\2.png"); Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("Select * from ServletDB where UserPassWord = 12 "); while (rs.next()) { InputStream imagedata = rs.getBinaryStream("image"); byte[] idata = new byte[8000]; int rec = imagedata.read(idata); fou.write(idata); idata = null; } st.close(); rs.close(); fou.close(); } catch (Exception ex ) { ex.printStackTrace(); } } try { conn.close(); } catch ( Exception ex ) { ex.printStackTrace(); } } 下载一个oracle.xml.sql.query.OracleXMLQuery包,里面可以有getXMLString()方法,通过它可以直接把图片的16进制原封不动的转换成XML中的字符串,在插入数据库的时候,将该字符串前面加上0x,不加引号,写入SQL语句中,通过调用oracle.jdbc.driver包,就可以存入数据库! 2000年是闰年吧,为什么3月1号到2月28号之间只间隔1天? indexOf()方法 what 数据抽象 and 过程抽象 简单的企业-ERP-项目用例图----急求所有表的设计(最好详细点啊包括各字段)---拜托各位啊!我刚学的 关于Servlet的一个问题 [200分]急速求助啊,JAVA语言编程谁可以用"雅可比迭代法"和"高斯-赛德尔迭代法"求解方程组啊 请问这该如何引用 怎样判断在JApplet的文本框输入的是不是数字? 菜鸟入门Java语言学习的要点 String 和 byte[] 怎样相互转化? 关于sun的java大家看怎么样? 我是java初学者,谁有好书推荐,帮忙者加分
Object source = e.getSource();
try
{
if (conn.isClosed())
conn = DriverManager.getConnection("jdbc:weblogic:mssqlserver4", props);
}
catch ( Exception ex )
{
ex.printStackTrace();
} if ( source == App.frame.jButton1 )
{
String StrSql = "insert into ServletDB values (?,?,?,?)"; try
{
File f = new File("c:\\1.png");
FileInputStream fin = new FileInputStream(f); PreparedStatement ps = conn.prepareStatement(StrSql);
ps.setString(1,"李丽华");
ps.setInt(2,12);
ps.setString(3,"RD");
int len = (int)f.length();
ps.setBinaryStream(4,fin,len); ps.executeUpdate(); ps.close(); fin.close(); }
catch ( Exception ex )
{
ex.printStackTrace();
}
}
else
{
try
{
FileOutputStream fou = new FileOutputStream("c:\\2.png"); Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("Select * from ServletDB where UserPassWord = 12 "); while (rs.next())
{
InputStream imagedata = rs.getBinaryStream("image"); byte[] idata = new byte[8000];
int rec = imagedata.read(idata);
fou.write(idata);
idata = null; } st.close();
rs.close();
fou.close();
}
catch (Exception ex )
{
ex.printStackTrace();
}
} try
{
conn.close();
}
catch ( Exception ex )
{
ex.printStackTrace();
}
}