This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes File Transfer DB Help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "File Transfer DB Help!" Watch "File Transfer DB Help!" New topic
Author

File Transfer DB Help!

Ve Ne
Greenhorn

Joined: May 26, 2005
Posts: 1
I have a longraw column in my Oracle Database. I converted it into Image Datatype in SQL Server...Now I wanna extract the files into my NT Folder. This is what I wrote. All microsoft files are opening (xls,doc,mpp,txt) but no pdf,jpg,bmp files are opening. Pls. help! what am i missing here? Is it because I converted Oracle Longraw to SQL server Image datatype or is something in the Java code missing or Java cannot handle?
***********************
import java.sql.*;
import java.io.*;

public class binext{
public static void main(String[] args) throws Exception{

String url = "jdbc:microsoft:sqlserver://<server name>DatabaseName=<Name>";
String uid = "<UID>";
String pw = "<password>";

try {// Load driver class
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch (java.lang.ClassNotFoundException e) {
System.err.println("ClassNotFoundException: " +e);
}
String Query;
int FileLength;
Connection cn;
ResultSet rs;
int file_id_seq;
String FileName;

file_id_seq = Integer.parseInt(args[0]);
FileName = args[1];

//instantiate the class
FileDBTransfer fdb = new FileDBTransfer();

Connection con = null;

con = DriverManager.getConnection(url,uid,pw);
rs = fdb.getRS(con,"SELECT document_data FROM sar_fac_file_cabinet where file_id_seq=" + file_id_seq);
fdb.getBinaryFile(args[1], rs);
con.close();

}//end main
}
[ June 02, 2005: Message edited by: Bear Bibeault ]
Rajasekar Kayamboo
Greenhorn

Joined: Sep 04, 2003
Posts: 9
Can you please post the error or exception (if any) you get in order to get a better idea of whatis happening?
regards,


Sekar
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

The image data type in SQL server has some restrictions when used in select statements, for example if the data stored in it is greater that 8000 bytes you can't simply include an image data type in a select statement. It needs to be handled via TSQL in a block by block manner. Have a read of the T-SQL documentation about the ReadText function.

This problem stems from SQL Server not really being designed to store large blocks of binary data. There are MS only technologies (such as ADO) which can work round this, but this it not going to work with Java. You might consider storing the files outside the DB and keeping a path to them in the DB, which is a much less problematic approach.
[ June 02, 2005: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Alin Sinpalean
Greenhorn

Joined: Jun 02, 2005
Posts: 6
> This problem stems from SQL Server not really being designed to store large
> blocks of binary data. There are MS only technologies (such as ADO) which can
> work round this, but this it not going to work with Java.

SQL Server is able to store LOBs without problems. Also, a good JDBC driver will be able to store and retrieve IMAGE and TEXT data just fine. Try jTDS, for example (disclaimer: I'm a jTDS developer). Use get/setBinaryStream() or get/setBlob().

Regarding the OPs problem: you could try to use a binary diff tool to see if and what gets broken. Also a post of the code behind could help, as well as the code you have used to move your data from Oracle to SQL Server.

Alin,
The jTDS Project.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File Transfer DB Help!
 
Similar Threads
problem while accessing class file from a package
Urgent....
how to convert .csv files into sql server files using java
reading data from jsp page to another jsp page using request.getParameter
about upload an image file to mssql database,help me !