Example using setcontenttype to write binary data?
Hi there,
I'm having trouble getting my jsp to read a binary file and send the response to an http client.
I'm not sure what it could be between the getWriter, getOutputStream, setcontenttype, and other methods involved.
Can anyone provide and/or point me to a simple example where a binary file is opened, read, and the contents sent back to a web-browser?
Thanks!
First, I would not recommend using JSP, but use servlets instead. If you have any newlines in the page like after <%@ page directives, you are can't write binary data. So you have to make all your page directives and everything have no newlines, making it ugly to read.
Second, use getOutputStream() to write to...
request.setContentType("application/octet-stream"); // or actual file mime type
request.setHeader("Content-Length", theFileSizeInBytes);
request.setHeader("Content-Disposition", "attachment; filename=" + theFileName); // if should do save as
OutputStream os = response.getOutputStream();
...
Similar Messages
-
I am trying to write a binary file to an SQL database (with two columns: ID and data). Using the subvi "Read from Binary File", the output is a String which I then try to write to a database. I can do this if two conditions are met:
The data type in the database is string based, such as nvarchar(MAX), varchar(MAX), text, etc.
The amount of data is less than 8000 bytes.
I am running into an issue where if I write more than 8k of data, I get the error: "String data, right truncation". My understanding is the data types I listed above are supposed to handle up to about 2GB, so this is confusing.
I'm not sure if this will make a difference, but I want to use a data type of varbinary(MAX). However, when I use the "Read from Binary File", I get a String output. When I try to write this to the database using "DB Tools Insert Data VI", I get the error:
"Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query."
I'm guessing "CONVERT" is part of the SQL query language and is a standard error returned by either the database or ODBC driver? In other words, not something I have direct access to? Is there a way to convert the data into something (binary) that the database will not complain about?
I'm just savvy enough in SQL to understand some of this functionality, but would consider myself a novice.
I appreciate any help!
Attachments:
WriteFileToDB.vi 16 KB
WriteFileToDB.png 36 KBAttached image file for reference.
Kudos are always welcome if you got solution to some extent.
I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
Attachments:
Binary in labview.jpg 38 KB -
The problem of using webservice to transfer binary data
I want to use webservice to realize downloading file , and then I think we can to transform the whole file to binary data ,and then use webservice to deliver these datas to client. but there is a promble. When the file size is a bit large , such as exceeding 1.5M , then client will receive error report. How to solve this promble. Another I think when server transforming the whole file to binary data , It should apply for much memory , as large as the file. I think this is not a good solution . Any one can give me some ideas ? How to realize download file using webservice(the server is oc4j)
839507 wrote:
the picture does not synchronize with sound. Why? Where is the problem??Dear Automotive Mechanic,
My car won't start, where is the problem?
Sincerly,
Captain Foss -
How to write binary data to browser - File Save dialog
Hi,
problem:
i have a working webservice and i get binary data from that webservice.
my dynpro java already works and i have byte[] b which has my binary result.
what i want:
when the user clicks on the button, the action onActionGetResult() is executed and inside this method, the byteArray b exists. what can i do, to say the dynpro application that it should send the binary data direct to the browser, so that the "File Save Dialog" appears and the user can save the file to the harddisk
any ideas?I've found the solution:
IWDWindow window = wdComponentAPI.getWindowManager().createNonModalExternalWindow(
res.getUrl(WDFileDownloadBehaviour.ALLOW_SAVE.ordinal()),
res.getResourceName());
window.show();
this worked for me -
hello,
in the attachement there is a picture where i save data in a binary file.i hope so.
the problem is that i only can read the binary file when the path is created with the 'File Dialog'.
why is it so??
markus
Attachments:
Binary.jpg 83 KBHi
You are using low level read and write functions and data types.
Please, take a look at datalogging examples, to understand how to write and read log files.
Hope it helps.
Alipio
"Qod natura non dat, Salmantica non praestat" -
Using JDBC to write a DAT file with delimiters to a database
Hi Everybody
I am new to JDBC and i am trying out some small applications: I downloaded this small program and tried to compile it and and I got the following errors: ( I have MySql installed). I have to set the classpath for the driver. But I am not sure why I am gettting the NullPointerException though)
I will be very gratefull to your help. Thanks a lot..
Loading JDBC Driver -> oracle.jdbc.driver.OracleDriver
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at us.ilango.WriteFileToTable.<init>(WriteFileToTable.java:69)
at us.ilango.WriteFileToTable.main(WriteFileToTable.java:367)
java.lang.NullPointerException
at us.ilango.WriteFileToTable.createTable(WriteFileToTable.java:97)
at us.ilango.WriteFileToTable.main(WriteFileToTable.java:368)
Exception in thread "main"
the Program is as follows:
package us.ilango;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.StringTokenizer;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.NumberFormat;
import java.text.ParseException;
* The following class provides an example of how to read a simple text file
* of records and then insert them into a table in a database. A text file
* named Employee.txt will contain employee records to be inserted into the
* following table:
* SQL> desc emp
* Name Null? Type
* EMP_ID NOT NULL NUMBER
* DEPT_ID NUMBER
* NAME NOT NULL VARCHAR2(30)
* DATE_OF_BIRTH NOT NULL DATE
* DATE_OF_HIRE NOT NULL DATE
* MONTHLY_SALARY NOT NULL NUMBER(15,2)
* POSITION NOT NULL VARCHAR2(100)
* EXTENSION NUMBER
* OFFICE_LOCATION VARCHAR2(100)
* NOTE: This example will provide and call a method that creates the EMP
* table. The name of the method is called createTable() and is called
* from the main() method.
public class WriteFileToTable {
final static String driverClass = "oracle.jdbc.driver.OracleDriver";
final static String connectionURL = "jdbc:oracle:thin:@localhost:1521:CUSTDB";
final static String userID = "scott";
final static String userPassword = "tiger";
final static String inputFileName = "Employee.txt";
final static String TABLE_NAME = "EMP";
final static String DELIM = ",";
Connection con = null;
* Construct a WriteFileToTable object. This constructor will create an
* Oracle database connection.
public WriteFileToTable() {
try {
System.out.print(" Loading JDBC Driver -> " + driverClass + "\n");
Class.forName(driverClass).newInstance();
System.out.print(" Connecting to -> " + connectionURL + "\n");
this.con = DriverManager.getConnection(connectionURL, userID, userPassword);
System.out.print(" Connected as -> " + userID + "\n");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
* Method used to create the initial EMP table. Before attempting to create
* the table, this method will first try to drop the table.
public void createTable() {
Statement stmt = null;
try {
stmt = con.createStatement();
System.out.print(" Dropping Table: " + TABLE_NAME + "\n");
stmt.executeUpdate("DROP TABLE " + TABLE_NAME);
System.out.print(" - Dropped Table...\n");
System.out.print(" Closing Statement...\n");
stmt.close();
} catch (SQLException e) {
System.out.print(" - Table " + TABLE_NAME + " did not exist.\n");
try {
stmt = con.createStatement();
System.out.print(" Creating Table: " + TABLE_NAME + "\n");
stmt.executeUpdate("CREATE TABLE emp (" +
" emp_id NUMBER NOT NULL " +
" , dept_id NUMBER " +
" , name VARCHAR2(30) NOT NULL " +
" , date_of_birth DATE NOT NULL " +
" , date_of_hire DATE NOT NULL " +
" , monthly_salary NUMBER(15,2) NOT NULL " +
" , position VARCHAR2(100) NOT NULL " +
" , extension NUMBER " +
" , office_location VARCHAR2(100))");
System.out.print(" - Created Table...\n");
System.out.print(" Closing Statement...\n");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
* Method used to read records from Employee.txt file then write the records
* to an Oracle table within the database named "EMP".
public void performLoadWrite() {
Statement stmt = null;
int insertResults = 0;
StringTokenizer st = null;
String emp_id;
String dept_id;
String name;
String date_of_birth;
String date_of_hire;
String monthly_salary;
String position;
String extension;
String office_location;
try {
System.out.print(" Creating Statement...\n");
stmt = con.createStatement ();
System.out.print(" Create FileReader Object for file: " + inputFileName + "...\n");
FileReader inputFileReader = new FileReader(inputFileName);
System.out.print(" Create BufferedReader Object for FileReader Object...\n");
BufferedReader inputStream = new BufferedReader(inputFileReader);
String inLine = null;
while ((inLine = inputStream.readLine()) != null) {
st = new StringTokenizer(inLine, DELIM);
emp_id = st.nextToken();
dept_id = st.nextToken();
name = st.nextToken();
date_of_birth = st.nextToken();
date_of_hire = st.nextToken();
monthly_salary = st.nextToken();
position = st.nextToken();
extension = st.nextToken();
office_location = st.nextToken();
System.out.print(" Inserting value for [" + name + "]\n");
insertResults = stmt.executeUpdate(
"INSERT INTO " + TABLE_NAME + " VALUES (" +
emp_id +
" , " + dept_id +
" , '" + name + "'" +
" , '" + date_of_birth + "'" +
" , '" + date_of_hire + "'" +
" , " + monthly_salary +
" , '" + position + "'" +
" , " + extension +
" , '" + office_location + "')");
System.out.print(" " + insertResults + " row created.\n");
System.out.print(" Commiting Transaction...\n");
con.commit();
System.out.print(" Closing inputString...\n");
inputStream.close();
System.out.print(" Closing Statement...\n");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
* Method used to query records from the database table EMP. This method
* can be used to verify all records have been correctly loaded from the
* example text file "Employee.txt".
public void queryRecords() {
Statement stmt = null;
ResultSet rset = null;
int deleteResults = 0;
int rowNumber = 0;
int emp_id;
int dept_id;
String name;
String date_of_birth;
Date date_of_birth_p;
String date_of_hire;
Date date_of_hire_p;
float monthly_salary;
String position;
int extension;
String office_location;
try {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
NumberFormat defaultFormat = NumberFormat.getCurrencyInstance();
System.out.print(" Creating Statement...\n");
stmt = con.createStatement ();
System.out.print(" Opening query for table: " + TABLE_NAME + "...\n");
rset = stmt.executeQuery ("SELECT * FROM emp ORDER BY emp_id");
while (rset.next ()) {
rowNumber = rset.getRow();
emp_id = rset.getInt(1);
if ( rset.wasNull() ) {emp_id = -1;}
dept_id = rset.getInt(2);
if ( rset.wasNull() ) {dept_id = -1;}
name = rset.getString(3);
if ( rset.wasNull() ) {name = "<null>";}
date_of_birth = rset.getString(4);
if ( rset.wasNull() ) {date_of_birth = "1900-01-01";}
try {
date_of_birth_p = formatter.parse(date_of_birth);
} catch (ParseException e) {
date_of_birth_p = new Date(0);
date_of_hire = rset.getString(5);
if ( rset.wasNull() ) {date_of_hire = "1900-01-01";}
try {
date_of_hire_p = formatter.parse(date_of_hire);
} catch (ParseException e) {
date_of_hire_p = new Date(0);
monthly_salary = rset.getFloat(6);
if ( rset.wasNull() ) {monthly_salary = 0;}
position = rset.getString(7);
if ( rset.wasNull() ) {position = "<null>";}
extension = rset.getInt(8);
if ( rset.wasNull() ) {extension = -1;}
office_location = rset.getString(9);
if ( rset.wasNull() ) {office_location = "<null>";}
System.out.print(
"\n" +
" RESULTS -> [R" + rowNumber + "] " + "\n" +
" Employee ID : " + emp_id + "\n" +
" Department ID : " + dept_id + "\n" +
" Employee Name : " + name + "\n" +
" D.O.B. : " + date_of_birth_p + "\n" +
" Date of Hire : " + date_of_hire_p + "\n" +
" Monthly Salary : " + defaultFormat.format(monthly_salary) + "\n" +
" Position : " + position + "\n" +
" Extension : x" + extension + "\n" +
" Office Location : " + office_location +
"\n");
System.out.print(" Closing ResultSet...\n");
rset.close();
System.out.print(" Closing Statement...\n");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
* Close down Oracle connection.
public void closeConnection() {
try {
System.out.print(" Closing Connection...\n");
con.close();
} catch (SQLException e) {
e.printStackTrace();
* Sole entry point to the class and application.
* @param args Array of String arguments.
* @exception java.lang.InterruptedException
* Thrown from the Thread class.
public static void main(String[] args)
throws java.lang.InterruptedException {
WriteFileToTable runExample = new WriteFileToTable();
runExample.createTable();
runExample.performLoadWrite();
runExample.queryRecords();
runExample.closeConnection();
}Hi
Thanks a lot. I ran the program with the MySql driver as follows:
The errors are as follows: I will ttry to place the Driver in the Classpath. As far as I know the driver has been specified correctly this time.
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at us.ilango.WriteAntennas.<init>(WriteAntennas.java:41)
at us.ilango.WriteAntennas.main(WriteAntennas.java:377)
java.lang.NullPointerException
at us.ilango.WriteAntennas.createTable(WriteAntennas.java:70)
at us.ilango.WriteAntennas.main(WriteAntennas.java:378)
Exception in thread "main" Loading JDBC Driver -> com.mysql.jdbc.Driver
The program is as follows:
package us.ilango;
* @author ilango
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.StringTokenizer;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
public class WriteAntennas {
final static String driverClass = "com.mysql.jdbc.Driver";
final static String connectionURL = "jdbc:mysql://localhost/test2";
final static String userID = "brian";
final static String userPassword = " ";
final static String inputFileName = "CO.DAT";
final static String TABLE_NAME = "CELL";
final static String DELIM = "|";
Connection con = null;
public WriteAntennas() {
try {
System.out.print(" Loading JDBC Driver -> " + driverClass + "\n");
Class.forName(driverClass).newInstance();
System.out.print(" Connecting to -> " + connectionURL + "\n");
this.con = DriverManager.getConnection(connectionURL, userID, userPassword);
System.out.print(" Connected as -> " + userID + "\n");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
* Method used to create the initial EMP table. Before attempting to create
* the table, this method will first try to drop the table.
public void createTable() {
Statement stmt=null;
try {
stmt = con.createStatement();
System.out.print(" Dropping Table: " + TABLE_NAME + "\n");
stmt.executeUpdate("DROP TABLE " + TABLE_NAME);
System.out.print(" - Dropped Table...\n");
System.out.print(" Closing Statement...\n");
stmt.close();
} catch (SQLException e) {
System.out.print(" - Table " + TABLE_NAME + " did not exist.\n");
try {
stmt = con.createStatement();
System.out.print(" Creating Table: " + TABLE_NAME + "\n");
stmt.executeUpdate("create table TOWER_PUBACC_CO (" +
"record_type char(2) null" +
", content_indicator char(3) null" +
", file_number char(8) null" +
", registration_number char(7) null" +
", unique_system_identifier long(9,0) not null" +
", coordinate_type char(1) not null" +
",latitude_degrees int null" +
",latitude_minutes int null" +
",latitude_seconds int(4,1) null" +
",latitude_direction char(1) null" +
",latitude_total_seconds int(8,1) null" +
",longitude_degrees int null" +
",longitude_minutes int null" +
",longitude_seconds int(4,1) null" +
",longitude_direction char(1) null" +
",longitude_total_seconds int(8,1) null)" );
System.out.print(" created Table...\n");
System.out.print(" closing Statement...\n");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
public void performLoadWrite() {
Statement stmt = null;
int insertResults = 0;
StringTokenizer st = null;
String record_type ;
String content_indicator;
String file_number ;
String registration_number;
String unique_system_identifier ;
String coordinate_type;
String latitude_degrees;
String latitude_minutes;
String latitude_seconds;
String latitude_direction;
String latitude_total_seconds;
String longitude_degrees;
String longitude_minutes;
String longitude_seconds;
String longitude_direction;
String longitude_total_seconds;
try {
System.out.print(" Creating Statement...\n");
stmt = con.createStatement ();
System.out.print(" Create FileReader Object for file: " + inputFileName + "...\n");
FileReader inputFileReader = new FileReader(inputFileName);
System.out.print(" Create BufferedReader Object for FileReader Object...\n");
BufferedReader inputStream = new BufferedReader(inputFileReader);
String inLine = null;
while ((inLine = inputStream.readLine()) != null) {
st = new StringTokenizer(inLine, DELIM);
record_type = st.nextToken();
content_indicator = st.nextToken();
file_number = st.nextToken();
registration_number = st.nextToken();
unique_system_identifier = st.nextToken();
coordinate_type =st.nextToken();
latitude_degrees = st.nextToken();
latitude_minutes = st.nextToken();
latitude_seconds=st.nextToken();
latitude_direction = st.nextToken();
latitude_total_seconds =st.nextToken();
longitude_degrees= st.nextToken();
longitude_minutes = st.nextToken();
longitude_seconds = st.nextToken();
longitude_direction=st.nextToken();
longitude_total_seconds =st.nextToken();
System.out.print(" Inserting value for [" + unique_system_identifier + "]\n");
insertResults = stmt.executeUpdate(
"INSERT INTO " + TABLE_NAME + " VALUES (" +
record_type +
" , " + content_indicator +
" , '" + file_number + "'" +
" , '" + registration_number + "'" +
" , '" + unique_system_identifier + "'" +
" , " + coordinate_type + "'" +
" , '" + latitude_degrees + "'" +
" , " + latitude_minutes + "'" +
" , '" + latitude_seconds + "'" +
" , '" + latitude_direction + "'" +
" , '" + latitude_total_seconds + "'" +
" , '" + longitude_minutes + "'" +
" , '" + longitude_seconds + "'" +
" , '" + longitude_direction + "'" +
" , '" + longitude_total_seconds + "')");
System.out.print(" " + insertResults + " row created.\n");
System.out.print(" Commiting Transaction...\n");
con.commit();
System.out.print(" Closing inputString...\n");
inputStream.close();
System.out.print(" Closing Statement...\n");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
public void queryRecords() {
Statement stmt = null;
ResultSet rset = null;
int deleteResults = 0;
int rowNumber = 0;
String record_type;
String content_indicator;
String file_number;
String registration_number ;
long unique_system_identifier;
String coordinate_type ;
int latitude_degrees ;
int latitude_minutes ;
int latitude_seconds;
String latitude_direction;
int latitude_total_seconds;
int longitude_degrees;
int longitude_minutes;
int longitude_seconds;
String longitude_direction;
int longitude_total_seconds;
try {
System.out.print(" Creating Statement...\n");
stmt = con.createStatement ();
System.out.print(" Opening query for table: " + TABLE_NAME + "...\n");
rset = stmt.executeQuery ("SELECT * FROM cell ORDER BY unique_system_identifier");
while (rset.next ()) {
rowNumber = rset.getRow();
unique_system_identifier = rset.getInt (1);
if ( rset.wasNull() ) {unique_system_identifier = -1;}
record_type = rset.getString (2);
if ( rset.wasNull() ) {record_type = "<null>";}
content_indicator = rset.getString(3);
if ( rset.wasNull() ) {content_indicator = "<null>";}
file_number = rset.getString(4);
if ( rset.wasNull() ) {file_number = "<null>";}
registration_number = rset.getString(5);
if ( rset.wasNull() ) {registration_number = "<null>";}
coordinate_type = rset.getString(6);
if ( rset.wasNull() ) {coordinate_type = "<null>";}
latitude_degrees = rset.getInt(7);
if ( rset.wasNull() ) {latitude_degrees = 1;}
latitude_minutes = rset.getInt(8);
if ( rset.wasNull() ) {latitude_minutes = 1;}
latitude_seconds = rset.getInt(9);
if ( rset.wasNull() ) {latitude_seconds = 1;}
latitude_direction = rset.getString(10);
if ( rset.wasNull() ) {latitude_direction = "<null>";}
latitude_total_seconds = rset.getInt(11);
if ( rset.wasNull() ) {latitude_total_seconds = 1;}
longitude_degrees = rset.getInt(12);
if ( rset.wasNull() ) {longitude_degrees = 1;}
longitude_minutes = rset.getInt(13);
if ( rset.wasNull() ) {longitude_minutes = 1;}
longitude_seconds = rset.getInt(14);
if ( rset.wasNull() ) {longitude_seconds = 1;}
longitude_direction = rset.getString(15);
if ( rset.wasNull() ) {longitude_direction = "<null>";}
longitude_total_seconds = rset.getInt(16);
if ( rset.wasNull() ) {longitude_total_seconds = 1;}
System.out.print(
"\n" +
" RESULTS -> [R" + rowNumber + "] " + "\n" +
" Unique_System_Identifier : " + unique_system_identifier + "\n" +
" Record_type : " + record_type + "\n" +
" Content_Indicator : " + content_indicator + "\n" +
" Registration_Number : " + registration_number + "\n" +
" File_Number : " + file_number + "\n" +
" Coordinate_Type : " + coordinate_type + "\n" +
" Latitude_Degrees : " + latitude_degrees + "\n" +
" Latitude_Minutes : " + latitude_minutes + "\n" +
" Latitude_Seconds : " + latitude_seconds + "\n" +
" Latitude_Direction : " + latitude_direction + "\n" +
" Latitude_Total_Seconds : " + latitude_total_seconds + "\n" +
" Longitude_Degrees : " + longitude_degrees + "\n" +
" longitude_minutes : " + longitude_minutes + "\n" +
" Longitude_Seconds : " + longitude_seconds + "\n" +
" longitude_direction : " + longitude_direction + "\n" +
" Longitude_Total_Seconds : " + longitude_total_seconds +
"\n");
System.out.print(" Closing ResultSet...\n");
rset.close();
System.out.print(" Closing Statement...\n");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
public void closeConnection() {
try {
System.out.print(" Closing Connection...\n");
con.close();
} catch (SQLException e) {
e.printStackTrace();
public static void main(String[] args)
throws java.lang.InterruptedException {
WriteAntennas runJob = new WriteAntennas();
runJob.createTable();
runJob.performLoadWrite();
runJob.queryRecords();
runJob.closeConnection();
} -
Use FDM to write mapped data TO (not from) E-Business Suite staging DB
Hello All,
Looking for the most efficient method to write FDM mapped data TO (not from) Oracle E-Business Suite staging DB.
Any thoughts/suggestions are most appreciated.You can use the data mart adapter to export the FDM Mapped Data to a file to be imported into EBS.
You could also use ERPI and use the writeback functionality. -
Download Binary Data File over Serial Port
I need help setting up a .vi that I can use to download a binary data file from a dos-based system. I will send the system a command, say ascii "DOWNLOAD", and then the remote system will send me a binary data file that will be approx. 600MB. I won't be doing any display/manipulation using labview, I will just need to have the option available in LV to recieve the file.
Any examples would help a programmer that is new to LV and is getting a little desperate.A VISA Read doesn't care whether the data it's getting is binary or ASCII. Where you might have problems is detecting that file transfer is complete. If you have enable termination character set to True in the VISA Configure Serial Port, the read will stop as soon as the termination character is detected. The default termination character is 0xA or a linefeed. You probably don't want to use this. If the file is terminated with a character or string of characters that you now will be unique, you can use this. If there is no unique termination character at the end of the file, the next best thing is to know the file size exactly and set the byte count of VISA Read to that number. Based on file size and baud rate, you would also need to adjust the VISA timeout value. Another way to do this is to transfer the data in pieces and write to a file as soon as the data is received. The reading of data would then be terminated when there are no more bytes available at the serial port. I've attached a LabVIEW 7.0 program that should give an idea of the last approach.
Attachments:
File Transfer.vi 57 KB -
Writing binary data in same format as with FORTRAN code
Hello,
I would like to write out data in a binary format that is used by FORTRAN unformatted direct access files. I have some code in FORTAN that produces the correct format; however, I have been unable to reproduce the output with a Java method.
The FORTAN code to write an array Z is:
REAL Z(72,46,16)
OPEN(8,FILE='grads.dat',FORM='UNFORMATTED',
& ACCESS='DIRECT',RECL=72*46)
IREC=1
DO 10 I=1,16
WRITE (8,REC=IREC) ((Z(J,K,I),J=1,72),K=1,46)
IREC=IREC+1
10 CONTINUE
The Java code I was able to come up with to write out an array arrTS produces binary data differently:
FileOutputStream fosOut = new FileOutputStream(filename,false);
for(int x=0; x<this.xmax; x++) {
for(int y=0; y<this.ymax; y++) {
ByteArrayOutputStream bosOut = new ByteArrayOutputStream(2);
DataOutputStream dos = new DataOutputStream(bosOut);
dos.writeFloat((float)this.arrTS[x][y]);
byte[] arrByte = bosOut.toByteArray();
fosOut.write(arrByte);
fosOut.close();
Any help is greatly appreciated.
Best regards,
StefanI am using a software to read in the data that I am calculating in Java. I cannot easily change the format that software is reading; therefore, ASCII is not an option.
The software that reads the data states something about "Little-endian". Do you which Java classes to use for that?
Best regards,
Stefan
First, you need to find out the format of yourFORTRAN
output. Is it ASCII? EBCDIC? BCD? IEEE?
Big-endian? Little-endian?
Until you know that you won't know which Javaclasses
to use.Also I wouldn't be too sure different FORTRAN
compilers use the same data format.
In my view the best system interchange format still is
the ASCII text file. Why don't you let the Fortran
program use it to write its data to file. It should be
no problem reading it from Java. -
Binary data in a servlet's doGet method?
Hi,
How to write binary data in a servlet's doGet method? Anyone, please help.Use POST instead of GET to transfer binary data. For GET, you can only append the data in the QUERY_STRING and its length is very limited. so better use POST.
-
Hi all I have a basic doubt. How does Servlets is preferred technology to generate binary data than JSP? Any limitation in JSP?
Okay,
When you write a JSP file, you type it in text, and all the text you type is sent to the client that requests your page. Everything is sent including carriage returns, spaces, tab characters and anything you have type into the file. Only things that are inside <% and %> do not get sent through. If you have several blank lines at the end of the file they will be sent to the client and may cause issues if you are writing binary data that needs to be handled by an application.
With Servlets you have to write data to the outputstream you get from the (cant quite remember) response.getOutputStream() method. This ensures that only what you want to send gets sent to the client.
It sepends on what you need it for. If it doesnt matter what you send through then JSP can be used to write binary data. In one application I had to send through sound files to the client and any extra data would only corrupt the sound, so it had to be sent using servlets.
Does that help? -
How to read a file with both text and binary data?
For text data I use a BufferedReader,
for binary data I use a DataInputStream.
Since readLine is deprecated in DataInputStream, how can I read in a proper way a file that contains some lines of text followed by some binary data.
Is there a way to do this without writing a new 'readLine' for DataInputStream (that has to take into account the different newlines for Unix en other OS's)?sorry about that ^
NEW STRING str
WHILE there is stuff in the file DO
getByte()
IF reading a string THEN
WHILE byte is not a return character DO
convert the byte to character/string
append char to str
WEND
ELSE IF reading raw data THEN
parse raw data
do stuff with it
END IF
WEND -
Hi,
We storing a Binary Data say "ù?" in oracle as String Datatype.
I have formed the query in my application to insert a record which has above string as one of the String field value.
The insertion was success but when the above string is not stored as it is but it is stored as "¿ù?" which is not a correct data.
Is this problem is because I'm using string for storing binary data?
Also please let me know what could be the best data type to store the binary data (like above data) in oracle.Justin,
With the help of your query I identified how the bytes are stored in the memory.
I'm having VARCHAR2 datatype of size 14 in oracle when ever i store my binary data it is storing as
127,0,0,0,0,0,0,0....for 14 bytes -> So the binary equivalent is 011111111,00000000,00000000,...... And i'm ok with it.
But the problem is whenever a byte is holding the binary equivalent of 128 it is storing in the oracle as 191
eq:
Bits: 10000000 => equivalent to 128 in decimal and it is what i want to get when i query it using select, but what i'm getting in sql query is "191".
Really I'm not able to understand the relationship beween 128 and 191 binary values.
I got the above detail using the DUMP sql function. -
DAQ vi to perform digital write and read measurements using 32 bits binary data saved in a file
Hi
DAQ vi to perform digital write and read measurements using 32 bits binary data saved in a file
Two main
sections:
1)
Perform
write and read operations to and fro different spread sheet files, such that
each file have a single row of 32bits different binary data (analogous to 1D
array) where the left most bit is the MSB. I don’t want to manually enter the
32 bits binary data, I want the data written or read just by opening a file
name saves with the intended data.
2)
And
by using test patterns implemented using the digital pattern generator or build digital data functions or otherwise, I need to
ensure that the
binary data written to a spreadsheet file or any supported file type
then through the NI-USB 6509 is same as the data read.
I’m aware I can’t use the simulated
device to read data written to any port but if the write part of the vi works I
‘m sure the read part will work on the physical device which I’ll buy later.
My Plan
of action
I’ve
created a basic write/read file task and a write/read DAQ task for NI USB 6509
and both combine in a while loop to form a progress VI which I’m confuse of how
to proceed with the implementation.
My
greatest problem is to link both together with the correct functions or operators
such that there are no syntax/execution errors and thus achieve my intended
result.
This
project is one of my many assignments for my master thesis, so please i’ll
appreciate every help as I’m not really efficient with LabVIEW programming but
I prefer it because is fun and interesting if I get to know it.
Currently I’m
practicing with LabVIEW 8.6/NI DAQmx 8.8 Demo versions and NI USB 6509
simulated device.
Please see
the attached file for my novice progress, thanks in
advance for the support
Rgds
Paul
Attachments:
DIO_write_read DAQ from file.vi 17 KBWhat does your file look like? The DAQmx write is expecting a single U32 value, not an array of I64.
Message Edited by vt92 on 09-16-2009 02:42 PM
"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal -
Using a servlet to send binary data
There is a section of our intranet that need to hold documents that have to be available only for a certain group of users. Here's my approach (if you think of a better one, please tell me):
1-all the files are in a directory upper than WWWRoot so that nobody can directly download them
2-there is a servlet that first: authentificate the user with username-password; and then lists all available documents.
3-When one of these docs is clicked, I want my servlet to open the file using filesystem File object and then copy the content of the selected file in the http response body. What object and method should I use to do so? I dont know if I should use FileReader or something else. Dont forget it will not only has to work with text files, but also with binary data files like swf, powerpointpresentation and the like. So I fear that objects such as FileRead will mess special characters up and corrupt data.
What would you advice me? Use FileReader or another object? Or maybe a completly different approach for the problem? And if you want to give me some sample codes, it would be appreciated.
Thx for your helpThere is something I dont understand.. its bizarre. Usually I dont understand why a script is not working, but now, I dont understand why a scritp is working..
Here are the codes that copy from a file to the servlet's ouput:
//basic response configurations
response.setContentType( mimeType );
ServletOutputStream out = response.getOutputStream();
//copy a file f to the servlet's output stream
File f = new File( path );
FileInputStream fis= new FileInputStream(f);
int available = fis.available();
byte[] b = new byte[available];
fis.read(b);
out.write( b );
out.flush();
They work fine. What I dont understand is that I tried them with a file of about 5 megs, and they still worked! I expected them to fail because the variable available is of the type int and then it implies that the maximum file size permitted by the algorithm should be 65536 bytes/1024=64 ko... isn't it????
Maybe you are looking for
-
IMac doesn't recognise JPEG on DVD
A DVD with JPEG files put on using Windows does not show any files on my IMac. Finder shows the DVD is empty. However the files and pictures show up on my Windows notebook. Any help appreciated
-
IWeb slideshow giving a 404 error when I publish to a folder
When I publish to a folder and post to my Verizon web space I get a 404 (not found) error on slideshows. I uploaded the same site to my office staging server and it works fine (see test link below) so it must be a problem with Verizon but I can't fig
-
Monitoring EWA in solution manager for EP
Hi How to monitor and configure the EP 7.0 on solution manager 7.0 for SP 16 Can any body give the doc and steps to do. Regards
-
HT4623 Can not get camera of photo to take video anyone have an answer
My iPad camera will not let me choose video. It won't go off photo. Any suggestions will be greatly appreciated.
-
Difference between Oracle 9i and 10g
hi, is there any document listing the major differences between 9i and 10g technology...