import java.io.*;
import java.sql.*; public class GetImage
{
public static void main(String args[])
{
String username;
String password;
String url;
String dropString;
String createString;
username = "root";
password = "root";
url = "jdbc:mysql://localhost/dangan"; try
{
Class.forName("org.gjt.mm.mysql.Driver");
} catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try
{
Connection con;
Statement stmt;
InputStream in=null;
con = DriverManager.getConnection(url, username, password);
System.out.println ("Ok, connection to the DB worked. Let's see if we can insert something:");
Statement stat=con.createStatement();
String sql="select size from image";
ResultSet rs=stat.executeQuery(sql);
while(rs.next())
{
in=rs.getBinaryStream("size");
}
FileOutputStream fileout=new FileOutputStream(new File("c:\\22.jpg"));
int size=in.available();
byte[] by=new byte[size];
in.read(by);
fileout.write(by,0,size);
fileout.close();
in.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
}
import java.sql.*; public class GetImage
{
public static void main(String args[])
{
String username;
String password;
String url;
String dropString;
String createString;
username = "root";
password = "root";
url = "jdbc:mysql://localhost/dangan"; try
{
Class.forName("org.gjt.mm.mysql.Driver");
} catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try
{
Connection con;
Statement stmt;
InputStream in=null;
con = DriverManager.getConnection(url, username, password);
System.out.println ("Ok, connection to the DB worked. Let's see if we can insert something:");
Statement stat=con.createStatement();
String sql="select size from image";
ResultSet rs=stat.executeQuery(sql);
while(rs.next())
{
in=rs.getBinaryStream("size");
}
FileOutputStream fileout=new FileOutputStream(new File("c:\\22.jpg"));
int size=in.available();
byte[] by=new byte[size];
in.read(by);
fileout.write(by,0,size);
fileout.close();
in.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货