• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

File Transfer DB Help!

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please post the error or exception (if any) you get in order to get a better idea of whatis happening?
regards,
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic