Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Well: first can i still use an TSSqlInput to have my db connector.
second : with the row i put a TjavaRow or Tjava ?
package routines;
import java.sql.*;
import java.io.*;
public class GetBlobFile {
public static void readBlob(int field_id) {
String driver = "net.sourceforge.jtds.jdbc.Driver";
String url = "jdbc:jtds:sqlserver://192.168.0.39:1433/talend;";
String user = "sa";
String passwd = "Phebe.22";
Connection conn = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(url, user, passwd);
PreparedStatement ps = conn
.prepareStatement("select image from blob2 where id = ?");
ps.setInt(1, field_id);
ResultSet rs = ps.executeQuery();
rs.next();
InputStream in = rs.getBinaryStream("image"); // image is the column
// name in real
// table
int length = in.available();
FileOutputStream out = new FileOutputStream("d:/file/test/out/"
+ field_id + ".png");
byte[] b = new byte;
int len = 0;
while ((len = in.read(b)) != -1) {
out.write(b, 0, len);
out.flush();
}
out.close();
in.close();
rs.close();
ps.close();
} catch (Exception ex) {
ex.printStackTrace(System.out);
} finally {
try {
conn.close();
} catch (Exception ex) {
}
}
}
}
Is there another way to do it right ?
Well: first can i still use an TSSqlInput to have my db connector.
second : with the row i put a TjavaRow or Tjava ?
package routines;
import java.sql.*;
import java.io.*;
public class GetBlobFile {
public static void readBlob(int field_id) {
String driver = "net.sourceforge.jtds.jdbc.Driver";
String url = "jdbc:jtds:sqlserver://192.168.0.39:1433/talend;";
String user = "sa";
String passwd = "Phebe.22";
Connection conn = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(url, user, passwd);
PreparedStatement ps = conn
.prepareStatement("select image from blob2 where id = ?");
ps.setInt(1, field_id);
ResultSet rs = ps.executeQuery();
rs.next();
InputStream in = rs.getBinaryStream("image"); // image is the column
// name in real
// table
int length = in.available();
FileOutputStream out = new FileOutputStream("d:/file/test/out/"
+ field_id + ".png");
byte[] b = new byte;
int len = 0;
while ((len = in.read(b)) != -1) {
out.write(b, 0, len);
out.flush();
}
out.close();
in.close();
rs.close();
ps.close();
} catch (Exception ex) {
ex.printStackTrace(System.out);
} finally {
try {
conn.close();
} catch (Exception ex) {
}
}
}
}