Connect Flat files using jdbc
Hi,
I have a problem with connecting flat files(.txt, .xml, .csv, .xls, etc...) which is existing in application it's self, using jdbc connection.
After searching I found some suggestions below.
1)xlsql
2)JDO
I tried with first one (xlsql), below is the process. First create core java project and load the jar files which is from xlsql. below is the code
Class.forName("com.nilostep.xlsql.jdbc.xlDriver");
final String dir = System.getProperty("user.dir")+"\\db\\xl";
conn = DriverManager.getConnection("jdbc:nilostep:excel:/"+dir);
Statement stmt = con.createStatement();
String sql = "select * from Sheet1$";
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()){
System.out.println(rs.getString(1));
}else{
System.out.println("nodata....");
It is saying Sheet1$ table not existing.
Please help me.
Not quite sure of your definition of a flat file, but a .xls files is a Microsoft Excel workbook, which is saved in a proprietary binary format, so there's certainly nothing 'flat' about it. Of course, there are odbc and suchlike drivers for treating Excel workbooks as data sources, but you need to ensure when you query them that you know the details of the workbook.
In each workbook, each spreadsheet has a name (as defined on it's tab at the bottom). That is taken to be the name of the 'table' that you use when you query it with SQL.
On each spreadsheet, row 1 of that sheet should denote the column names of the 'table'
All subsequent rows on the spreadsheet are the data that will be returned from querying it.
Typically, the data on the sheets should be fairly straightforward, in order to query it. Some excel functionality may prevent it being queried properly.
Similar Messages
-
Delete data from a flat file using PL/SQL -- Please help.. urgent
Hi All,
We are writing data to a flat file using Text_IO.Put_Line command. We want to delete data / record from that file after data is written onto it.
Please let us know if this is possible.
Thanks in advance.
VaishaliThere's nothing in UTL_FILE to do this, so your options are either to write a Java stored procedure to do it or to use whatever mechanism the host operating system supports for editing files.
Alternatively, you could write a PL/SQL procedure to read each line in from the file and then write them out to a second file, discarding the line you don't want along the way. -
Writing to a flat file using UTL in a procedure
Hello All,
I am creating a procedure in which I am trying to write data to a flat file using UTL. Code is shown below:
CREATE OR REPLACE PROCEDURE wrt_lifungduty IS
sql_stmt varchar2(200);
sql_stmt1 varchar2(200);
sql_stmt2 varchar2(200);
v_cur_hdl integer;
v_rows_processed BINARY_INTEGER;
V_file UTL_FILE.FILE_TYPE;
V_flatfile_line VARCHAR2(98) := NULL;
V_OBLIGATION_KEY NUMBER(10);
V_OBLIGATION_LEVEL VARCHAR2(6);
V_KEY_VALUE_1 VARCHAR2(20);
V_KEY_VALUE_2 VARCHAR2(20);
V_PARTNER_TYPE VARCHAR2(6);
V_PARTNER_ID VARCHAR2(10);
V_EXT_INVC_NO VARCHAR2(30);
V_EXT_INVC_DATE DATE;
V_PAID_DATE DATE;
V_PAID_AMT NUMBER(20,4);
V_COMP_ID VARCHAR2(10);
V_RECEIPT_DATE DATE;
V_ORDER_QTY NUMBER(12,4);
V_RECEIPT_QTY NUMBER(12,4);
V_FRT NUMBER;
V_DUTY NUMBER;
V_SUPPLIER NUMBER;
V_FLAG VARCHAR2(1);
V_ELC_COST NUMBER;
V_ADJ_ELC NUMBER;
Cursor x is
select OBLIGATION_KEY,OBLIGATION_LEVEL,KEY_VALUE_1,KEY_VALUE_2,PARTNER_TYPE,PARTNER_ID,EXT_INVC_NO,EXT_INVC_DATE
,PAID_DATE,PAID_AMT,COMP_ID,RECEIPT_DATE,ORDER_QTY,RECEIPT_QTY,FRT,DUTY,SUPPLIER,FLAG,ELC_COST,ADJ_ELC
from RMSBIZ.CT_ANALYZE_LIFUNG_DUTY;
BEGIN
if not UTL_FILE.IS_OPEN(V_file) then
V_file := UTL_FILE.FOPEN('/exchange/biz/rms2lan','sb_duty.dat','w'); --need to give the location for testing
end if;
for x1 in x loop
V_OBLIGATION_KEY :=1;
V_OBLIGATION_LEVEL :='test';
V_OBLIGATION_KEY :=x1.OBLIGATION_KEY;
V_OBLIGATION_LEVEL :=x1.OBLIGATION_LEVEL;
V_KEY_VALUE_1 :=x1.KEY_VALUE_1;
V_KEY_VALUE_2 :=x1.KEY_VALUE_2;
V_PARTNER_TYPE :=x1.PARTNER_TYPE;
V_PARTNER_ID :=x1.PARTNER_ID;
V_EXT_INVC_NO :=x1.EXT_INVC_NO;
V_EXT_INVC_DATE :=x1.EXT_INVC_DATE;
V_PAID_DATE :=x1.PAID_DATE;
V_PAID_AMT :=x1.PAID_AMT;
V_COMP_ID :=x1.COMP_ID;
V_RECEIPT_DATE :=x1.RECEIPT_DATE;
V_ORDER_QTY :=x1.ORDER_QTY;
V_RECEIPT_QTY :=x1.RECEIPT_QTY;
V_FRT :=x1.FRT;
V_DUTY :=x1.DUTY;
V_SUPPLIER :=x1.SUPPLIER;
V_FLAG :=x1.FLAG;
V_ELC_COST :=x1.ELC_COST;
V_ADJ_ELC :=x1.ADJ_ELC;
V_flatfile_line:= V_OBLIGATION_KEY||','||
V_OBLIGATION_LEVEL ||','||
V_KEY_VALUE_1 ||','||
V_KEY_VALUE_2 ||','||
V_PARTNER_TYPE ||','||
V_PARTNER_ID ||','||
V_EXT_INVC_NO ||','||
V_EXT_INVC_DATE ||','||
V_PAID_DATE ||','||
V_PAID_AMT ||','||
V_COMP_ID ||','||
V_RECEIPT_DATE ||','||
V_ORDER_QTY ||','||
V_RECEIPT_QTY ||','||
V_FRT ||','||
V_DUTY ||','||
V_SUPPLIER ||','||
V_FLAG ||','||
V_ELC_COST ||','||
V_ADJ_ELC;
V_flatfile_line:= V_OBLIGATION_KEY||','|| V_OBLIGATION_LEVEL;
UTL_FILE.PUT_LINE(V_file, V_flatfile_line);
end loop
commit;
UTL_FILE.fclose(V_file);
END;
Getting the following errors:
SQL>Welcome-->
ERROR at line 1:
ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at "SYS.UTL_FILE", line 98
ORA-06512: at "SYS.UTL_FILE", line 157
ORA-06512: at "RMSBIZ.WRT_LIFUNGDUTY", line 39
ORA-06512: at line 1
SQL>Welcome-->39
39* V_file := UTL_FILE.FOPEN('/exchange/biz/rms2lan','sb_duty.dat','w');
SQL>Welcome-->
Does any one know why it is erroring out?
Thanks,
Chiruthe code below works if i take out the last 3 columns while writing to the flat file line.
CREATE OR REPLACE PROCEDURE wrt_lifungduty IS
sql_stmt varchar2(200);
sql_stmt1 varchar2(200);
sql_stmt2 varchar2(200);
v_cur_hdl integer;
v_rows_processed BINARY_INTEGER;
V_file UTL_FILE.FILE_TYPE;
V_flatfile_line VARCHAR2(98) := NULL;
V_OBLIGATION_KEY NUMBER(10);
V_OBLIGATION_LEVEL VARCHAR2(6);
V_KEY_VALUE_1 VARCHAR2(20);
V_KEY_VALUE_2 VARCHAR2(20);
V_PARTNER_TYPE VARCHAR2(6);
V_PARTNER_ID VARCHAR2(10);
V_EXT_INVC_NO VARCHAR2(30);
V_EXT_INVC_DATE DATE;
V_PAID_DATE DATE;
V_PAID_AMT NUMBER(20,4);
V_COMP_ID VARCHAR2(10);
V_RECEIPT_DATE DATE;
V_ORDER_QTY NUMBER(12,4);
V_RECEIPT_QTY NUMBER(12,4);
V_FRT NUMBER;
V_DUTY NUMBER;
V_SUPPLIER NUMBER;
V_FLAG VARCHAR2(1);
V_ELC_COST VARCHAR2(20);
V_ADJ_ELC VARCHAR2(20);
Cursor x is
select OBLIGATION_KEY,OBLIGATION_LEVEL,KEY_VALUE_1,KEY_VALUE_2,PARTNER_TYPE,PARTNER_ID,EXT_INVC_NO,EXT_INVC_DATE
,PAID_DATE,PAID_AMT,COMP_ID,RECEIPT_DATE,ORDER_QTY,RECEIPT_QTY,FRT,DUTY,SUPPLIER,FLAG,ELC_COST,ADJ_ELC
from RMSBIZ.CT_ANALYZE_LIFUNG_DUTY;
BEGIN
if not UTL_FILE.IS_OPEN(V_file) then
V_file := UTL_FILE.FOPEN('/rmsapps/rms803/biz/data/utl_files','sb_duty.csv','w'); --need to give the location for testing
end if;
for x1 in x loop
V_OBLIGATION_KEY :=nvl(x1.OBLIGATION_KEY,null);
V_OBLIGATION_LEVEL :=nvl(x1.OBLIGATION_LEVEL,null);
V_KEY_VALUE_1 :=x1.KEY_VALUE_1;
V_KEY_VALUE_2 :=x1.KEY_VALUE_2;
V_PARTNER_TYPE :=x1.PARTNER_TYPE;
V_PARTNER_ID :=x1.PARTNER_ID;
V_EXT_INVC_NO :=x1.EXT_INVC_NO;
V_EXT_INVC_DATE :=x1.EXT_INVC_DATE;
V_PAID_DATE :=x1.PAID_DATE;
V_PAID_AMT :=x1.PAID_AMT;
V_COMP_ID :=x1.COMP_ID;
V_RECEIPT_DATE :=x1.RECEIPT_DATE;
V_ORDER_QTY :=x1.ORDER_QTY;
V_RECEIPT_QTY :=x1.RECEIPT_QTY;
V_FRT :=x1.FRT;
V_DUTY :=x1.DUTY;
V_SUPPLIER :=x1.SUPPLIER;
V_FLAG :=nvl(x1.FLAG,'0');
V_ELC_COST :=to_char(nvl(x1.ELC_COST,0));
V_ADJ_ELC :=to_char(nvl(x1.ADJ_ELC,0));
V_flatfile_line:= V_OBLIGATION_KEY||','||
V_OBLIGATION_LEVEL ||','||
V_KEY_VALUE_1 ||','||
V_KEY_VALUE_2 ||','||
V_PARTNER_TYPE ||','||
V_PARTNER_ID ||','||
V_EXT_INVC_NO ||','||
V_EXT_INVC_DATE ||','||
V_PAID_DATE ||','||
V_PAID_AMT ||','||
V_COMP_ID ||','||
V_RECEIPT_DATE ||','||
V_ORDER_QTY ||','||
V_RECEIPT_QTY ||','||
V_FRT ||','||
V_DUTY ||','||
V_SUPPLIER ||','||
-- V_FLAG ||','||
V_ELC_COST ||','||
V_ADJ_ELC;
UTL_FILE.PUT_LINE(V_file, V_flatfile_line);
end loop
commit;
UTL_FILE.fclose(V_file);
EXCEPTION
WHEN UTL_FILE.INVALID_PATH
THEN
DBMS_OUTPUT.PUT_LINE ('error: INVALID_PATH');
WHEN UTL_FILE.INVALID_MODE
THEN
DBMS_OUTPUT.PUT_LINE ('error: INVALID_MODE');
WHEN UTL_FILE.INVALID_FILEHANDLE
THEN
DBMS_OUTPUT.PUT_LINE ('error: INVALID_FILEHANDLE');
WHEN UTL_FILE.INVALID_OPERATION
THEN
DBMS_OUTPUT.PUT_LINE ('error: INVALID_OPERATION');
WHEN UTL_FILE.READ_ERROR
THEN
DBMS_OUTPUT.PUT_LINE ('error: READ_ERROR');
WHEN UTL_FILE.WRITE_ERROR
THEN
DBMS_OUTPUT.PUT_LINE ('error: WRITE_ERROR');
WHEN UTL_FILE.INTERNAL_ERROR
THEN
DBMS_OUTPUT.PUT_LINE ('error: INTERNAL_ERROR');
WHEN OTHERS THEN
-- v_error_code := SQLCODE;
-- v_error_message := SQLERRM;
-- dbms_output.put_line('ERROR: '||v_error_code);
-- dbms_output.put_line('ERROR: '||v_error_message);
RAISE_APPLICATION_ERROR(-20003,'sbduty - aborted');
END;
/It fails as soon as it encounters the V_FLAG in the V_flat_file_line. The data in the table has nulls for the FLAG, and some -ve numbers for the ELC_COST,ADJ_ELC..but that should'nt cause any problems does it?
Whats wrong with those 3 columns?
Errors that i get are:
SQL>Welcome-->BEGIN wrt_lifungduty; END;
ERROR at line 1:
ORA-20003: sbduty - aborted
ORA-06512: at "RMSBIZ.WRT_LIFUNGDUTY", line 117
ORA-06512: at line 1
SQL>Welcome-->117
117* RAISE_APPLICATION_ERROR(-20003,'sbduty - aborted');
SQL>Welcome-->
Thanks,
Chiru -
Can't read special characters in an excel file using JDBC
Hi! I 've a code to read an excel file using JDBC-ODBC bridge. I can read the values, but any special characters is readed wrong, just symbols. The special characters are of spanish language. This is my code:
Locale currentLocale;
currentLocale = new Locale("es", "MX");
Locale.setDefault(currentLocale);
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
c = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=comisionesperfiles.xls");
stmnt = c.createStatement();
String query = "Select * from [Hoja1$]" ;
ResultSet rs = stmnt.executeQuery( query );
while( rs.next() ){
String valor = rs.getString(2) ;
if(valor != null && !"null".equalsIgnoreCase(valor)){
if(!comisiones.contains(valor)){
System.out.println(valor);
comisiones.add( valor );
rs.close();
stmnt.close();As you can see, I've tried to set the locale, but it didn't work.
I'm using Excel 2003, Java Version 1.4.2_07 and Windows XP Professional (in latin american spanish).
Hope someone can help me!FYI: Apache's POI can read/write Excel files in Java:
http://jakarta.apache.org/poi/index.html -
How to get field separator in flat file using GUI_DOWNLOAD function
hi,
how to get field separator in flat file using GUI_DOWNLOAD function.
thanking you.Hi,
Use WRITE_FIELD_SEPARATOR = 'X'.
Check this sample code
REPORT z_file_download.
DATA: w_name(90) TYPE c.
DATA:
BEGIN OF fs_flight,
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
price LIKE sflight-price,
currency LIKE sflight-currency,
END OF fs_flight.
DATA:
BEGIN OF fs_head,
carrid(10) TYPE c,
connid(10) TYPE c,
fldate(10) TYPE c,
price(10) TYPE c,
curr(10) TYPE c,
END OF fs_head.
DATA:
t_head LIKE
TABLE OF
fs_head.
DATA:
t_flight LIKE
TABLE OF
fs_flight.
fs_head-carrid = 'CARRID'.
fs_head-connid = 'CONNID'.
fs_head-fldate = 'FLDATE'.
fs_head-price = 'PRICE'.
fs_head-curr = 'CURRENCY'.
APPEND fs_head TO t_head.
SELECT-OPTIONS:
s_carrid FOR fs_flight-carrid.
START-OF-SELECTION.
SELECT carrid
connid
fldate
price
currency
FROM sflight
INTO TABLE t_flight
WHERE carrid IN s_carrid.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = 'D:\flight.xls'
FILETYPE = 'ASC'
* APPEND = ' '
WRITE_FIELD_SEPARATOR = 'X'
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* IMPORTING
* FILELENGTH =
tables
data_tab = t_head
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'D:\flight.xls'
filetype = 'ASC'
append = 'X'
write_field_separator = 'X'
TABLES
data_tab = t_flight
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc EQ 0.
MESSAGE 'Download successful' TYPE 'I'.
ENDIF.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. -
How to Create a Flat File using FTP/File Adapter
Can any body done workaround on creating the Flat file using FTP/File Adapter?.
I need to create a simple FlatFile either using of delimiter/Fixed length. using the above said adapters we can create XML file, i tried concatinating all the values into a single String and writing into a file, but it does not have proper structure
Can any body help me out on this..
Thanks
RamYou can create a text schema while creating a File Adapter. If schema is specified for File Adapter, it takes care of converting XML into fixed length or delimited format.
Thanks,
-Ng. -
Idoc to flat file using Integration process does not show up at all
Hello All,
I created a scenario IDOC to Flat File using Integration Process and one without IntegrationProcess. I am able to execute the one without Integration Process easily.
However when I send the IDOC from SAP then the Integration Process scenario just does not work.
I Checked SXMB_MONI There is no entry for the Integration Process.I can see entry for other without Integration Process.
SXI_CACHE : I can see my Integration Process active
SWEQADM : I have activated the Event Queue and Background job
SWF_XI_ADM_BPE : ALL BPE is showing green status.
All syntax check on IP are fine.
There is no Basis Help for me so there could be some additional basis steps which need to be configured. Has anyone faced such an issue with Integration Process?
Regards
PrashantaHope this might help you. when u configure an IDoc as Sender with BPM this is how you proceed.
<b>1<b>. let us split the scenario into two</b>.</b>
a. <b>Sender to BPM</b> ( Integration Process).
b. <b>BPM to Receiver</b>.
<b>2. First let us configure the first Sender to BPM.</b>
a. Sender Agreement( <b>Not required</b> ).
b. Receiver Agreement( <b>NOT Required</b>).
c. Receiver Determination( Sender Service, Outbound Interface, Receiver Service(<b>Integration Process</b>).
d. Interface Determination( Inbound Interface(Sender Abstract Interface), Message Mapping(NOT Required if your using transformation stepin Integration Process)).
<b>3. Now let us configure the Second BPM to Receiver.</b>
a. Sender Agreement( <b>NOT Required</b>)
b. Receiver Agreement( Sender Service(<b>Integration process</b>), Receiver Abstarct Interface,Receiver service, Inbound Interface).
c. Receiver Determination( Sender Service(Integration Process), Receiver Abstarct Interface,Receiver Service).
d. Interface Determination( Inbound Interface, Message Mapping(<b>NOT Required</b>)).
So Finally we have <b>One Receiver Agreement</b>, <b>Two Receiver Determinations</b>, <b>Two Interface Determinations</b>.
Please let me know if you have any more queries.
Regards
Gopi -
How to extract data from Essbase to Flat File using ODI
Hi,
Anyone know how to extract data from Essbase to Flat File using ODI?
Thanks in advance.
Regards,
SumardiHi,
Have you read through :-
Oracle Data Integrator Adapter for Hyperion Essbase Getting Started - http://download.oracle.com/docs/cd/E10530_01/doc/epm.931/odiess_getting_started.pdf
Oracle Data Integrator Adapter for Hyperion Essbase User's Guide - http://download.oracle.com/docs/cd/E10530_01/doc/epm.931/odiess_users.pdf
If you have read them and are still have a problem at what stage are you having the issues?
Cheers
John
http://john-goodwin.blogspot.com/ -
Connecting to Oracle using JDBC
Hi all,
I am a new to Oracle. I am trying to connect to Oracle using JDBC
The URL with which I tried to connect was:
jdbc:oracle:oci8:@myServiceName,user='myLogin',password='myPassword'
I get an error (ORA-12154)
- TNS could not resolve service name
When I use the same userid, password and service and connect thru' SQL*Plus it goes thru'. Is there any parameter which I am missing. Can anyone throw some light on this. I am held up with this issue badly.
Thanks for all your help and time.
Regards,
LathaHi Latha,
Please try to use thin and add port number.
m_conn = DriverManager.getConnection("jdbc:oracle:thin:@" + hostURL + ":" + port + ":" + database, user, password);
Hong
null -
Compile a procedure /SQL file using JDBC?
Is there a way we can compile a procedure or even a smiple SQL file using JDBC?
Or in other words can "@ <file name with path>" be done using JDBC? Has anyone tried this before?
I have five different databases, and i want to be able to compile my stored procedures at once on all my 5 databases. So, if we know if this is possible in JDBC?
THanksright, as a matter of fact i wanted some pointers on how to run these SQL commands using JDBC.
Like, set serveroutput on
set feedback on
@ filename or start filename
show error
etc. -
DB2 Version 8 to Flat Files using ODI
Hi,
We are trying to load data from DB2 V8 to flat files using ODI.
Can anybody help me in this to configure server in Topology.
Thanks
AshwiniHi,
How are you? Let me try contribute a little...
A)
1) The OS isn't a problem, once you link it at topology will be OK.
2) If you have a fix name just create a datastore to it, if not, there are techniques to got dynamic file names
3) When you say "*.dat, *.cvs" maybe you refer to the internal format of file (record separator, decimal point, etc) all of this is configurable on datastore that represents the file at ODI.
B) Yes, the only requisite is to have the write and read rights.
C) The most simple way is create a refresh variable that get the data in any format you wish..
Does it make any sense to you?
Cezar Santos -
Loading big XML files using JDBC gives errors
Hi,
I've created a XMLType table using binary storage, with the restriction that any document stored has a (any) schema:
CREATE TABLE XMLBIN OF XMLTYPE
XMLTYPE STORE AS BINARY XML
ALLOW ANYSCHEMA;Then I use JDBC to store a relatively large document using the following code:
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String connectionString = "jdbc:oracle:thin:@host:1521:sid";
File f = new File("c:\\temp\\big.xml");
Connection conn = DriverManager.getConnection(connectionString, "username", "password");
XMLType xml = XMLType.createXML(conn,new FileInputStream(f));
String statementText = "INSERT INTO xmlbin VALUES (?)";
OracleResultSet resultSet = null;
OracleCallableStatement statement = (OracleCallableStatement)conn.prepareCall(statementText);
statement.setObject(1,xml);
statement.execute();
statement.close();
conn.commit();
conn.close();Loading a file of 61Mb (real Mb, in non-IT Mb (where 1Mb seems to be 10^6) it is 63.9Mb) or less doesn't give any errors, loading a file bigger then that gives the following error:
java.sql.SQLRecoverableException: Io exception: Software caused connection abort: socket write error
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:101)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:229)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:458)
at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:960)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1222)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3381)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3482)
at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:3856)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1373)
at jdbctest.Tester.main(Tester.java:60)A succesful insert of a 63Mb file takes about 23 seconds to execute. The 70Mb file fails already after a few seconds, so I'm ruling out any time outs.
I'm guessing there are some buffers that need to be enlarged, but don't have a clue which ones.
Anyone any idea what might cause the problem and how to resolve?
My server runs Oracle 11g Win32. The client is Windows running Sun Java 1.6, using ojdbc6.jar and Oracle 11g Client installed.
Cheers,
HaraldHi Mark,
The trace log in the OEM shows me:
Errors in file d:\oracle11g\app\helium\diag\rdbms\helium\helium\trace\helium_ora_6948.trc (incident=7510): ORA-07445: exception encountered: core dump [__intel_new_memcpy()+613] [ACCESS_VIOLATION] [ADDR:0x0] [PC:0x6104B045] [UNABLE_TO_WRITE] [] If needed I can post the full contents (if I find out how, am still a novice :-))
Cheers,
Harald -
Reading data from flat file Using TEXT_IO
Dear Gurus
I already posted this question but this time i need some other changes .....Sorry for that ..
I am using 10G forms and using TEXT_IO for reading data from flat file ..
My data is like this :-
0|BP-V1|20100928|01|1|2430962.89|27|2430962.89|MUR|20100928120106
9|2430962.89|000111111111|
1|61304.88|000014104113|
1|41961.73|000022096086|
1|38475.65|000023640081|
1|49749.34|000032133154|
1|35572.46|000033093377|
1|246671.01|000042148111|
Here each column is separated by | . I want to read all the columns and want to do some validation .
How can i do ?
Initially my requirement was to read only 2 or 3 columns so i did like this ...
Procedure Pay_Simulator(lfile_type varchar2,lac_no varchar2,lcur varchar2,lno_item number,ltotal number,ldate date,lpay_purp varchar2,lfile_name varchar2)
IS
v_handle utl_file.file_type;
v_filebuffer varchar2(500);
line_0_date VARCHAR2 (10);
line_0_Purp VARCHAR2 (10);
line_0_count Number;
line_0_sum number(12,2);
line_0_ccy Varchar2(3);
line_9_sum Number(12,2);
line_9_Acc_no Varchar2(12);
Line_1_Sum Number(12,2);
Line_1_tot Number(15,2) := 0;
Line_1_flag Number := 0;
lval number;
lacno varchar2(16);
v_file varchar2(20);
v_path varchar2(50);
Begin
v_file := mcb_simulator_pkg.GET_FILENAME(lfile_name); -- For the file name
v_path :=rtrim(regexp_substr( lfile_name , '.*\\' ),'\'); For the Path
v_path := SUBSTR (lfile_name,0, INSTR (lfile_name, '\', -1));
v_handle := UTL_FILE.fopen (v_path, v_file, 'r');
LOOP
UTL_FILE.get_line (v_handle, v_filebuffer);
IF SUBSTR (v_filebuffer, 0, 1) = '0' THEN
SELECT line_0 INTO line_0_date
FROM (SELECT LTRIM (REGEXP_SUBSTR (v_filebuffer, '[^|]+{1}', 1, LEVEL)) line_0, ROWNUM rn
FROM DUAL
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (v_filebuffer, '[^|]*')) + 1)
WHERE rn = 3;
SELECT line_0 INTO line_0_Purp
FROM (SELECT LTRIM (REGEXP_SUBSTR (v_filebuffer, '[^|]+{1}', 1, LEVEL)) line_0, ROWNUM rn
FROM DUAL
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (v_filebuffer, '[^|]*')) + 1)
WHERE rn = 4;
SELECT line_0 INTO line_0_count
FROM (SELECT LTRIM (REGEXP_SUBSTR (v_filebuffer, '[^|]+{1}', 1, LEVEL)) line_0, ROWNUM rn
FROM DUAL
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (v_filebuffer, '[^|]*')) + 1)
WHERE rn = 7;
SELECT line_0 INTO line_0_sum
FROM (SELECT LTRIM (REGEXP_SUBSTR (v_filebuffer, '[^|]+{1}', 1, LEVEL)) line_0, ROWNUM rn
FROM DUAL
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (v_filebuffer, '[^|]*')) + 1)
WHERE rn = 8;
SELECT line_0 INTO line_0_ccy
FROM (SELECT LTRIM (REGEXP_SUBSTR (v_filebuffer, '[^|]+{1}', 1, LEVEL)) line_0, ROWNUM rn
FROM DUAL
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (v_filebuffer, '[^|]*')) + 1)
WHERE rn = 9;
ELSIF SUBSTR (v_filebuffer, 0, 1) = '9' THEN
SELECT line_9 INTO line_9_Acc_no
FROM (SELECT LTRIM (REGEXP_SUBSTR (v_filebuffer, '[^|]+{1}', 1, LEVEL)) line_9, ROWNUM rn
FROM DUAL
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (v_filebuffer, '[^|]*')) + 1)
WHERE rn = 3;
SELECT line_9 INTO line_9_sum
FROM (SELECT LTRIM (REGEXP_SUBSTR (v_filebuffer, '[^|]+{1}', 1, LEVEL)) line_9, ROWNUM rn
FROM DUAL
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (v_filebuffer, '[^|]*')) + 1)
WHERE rn = 2;
ELSIF SUBSTR (v_filebuffer, 0, 1) = '1' THEN
line_1_flag := line_1_flag+1;
SELECT line_1 INTO line_1_sum
FROM (SELECT LTRIM (REGEXP_SUBSTR (v_filebuffer, '[^|]+{1}', 1, LEVEL)) line_1, ROWNUM rn
FROM DUAL
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (v_filebuffer, '[^|]*')) + 1)
WHERE rn = 3;
Line_1_tot := Line_1_tot + line_1_sum;
END IF;
END LOOP;
DBMS_OUTPUT.put_line (Line_1_tot);
DBMS_OUTPUT.PUT_LINE (Line_1_flag);
UTL_FILE.fclose (v_handle);
END;
But now how can i do ? Shall i use like this select Statement for all the columns ?Sorry for that ..
As per our requirement ...
I need to read the flat file and it looks like like this .
*0|BP-V1|20100928|01|1|2430962.89|9|2430962.89|MUR|20100928120106*
*9|2430962.89|000111111111|*
*1|61304.88|000014104113|*
*1|41961.73|000022096086|*
*1|38475.65|000023640081|*
*1|49749.34|000032133154|*
*1|35572.46|000033093377|*
*1|246671.01|000042148111|*
*1|120737.25|000053101979|*
*1|151898.79|000082139768|*
*1|84182.34|000082485593|*
I have to check the file :-
Validation are 1st line should start from 0 else it should raise an error and insert that error into one table .
The for 2nd line also same thing ..it should start from 9 else it should raise an error and insert that error into one table .
Then the 3rd line should start from 1 else it should raise an error and insert that error into one table .
After that i have to do a validation like i will read the 1st line 2nd column .. It should be like this BP-V1 else raise an error and insert that error to a table . Then i will check the 3rd column which is 20100928 , it should be YYYYMMDD format else same thing ERROR.
Then like this for all columns i have different validation .......
Then it will check for the 2nd line 3rd column . this is an account no .1st i will check it should be 12 char else ERROR .Then I will check that what user has imputed in the form.Like for example User putted 111111111 then i will check with this 000111111111 which is there in the 2nd line . I have to add 000 before that Account no which user imputed .
Then the lines which is starting from 1 , i have to take all the 2nd column for all the lines which is starting from 1 and i have to do a sum . After that i have to compare that sum with the value in the 1st lines ( Starting from 0) 6th column . It should be same else ERROR ...
Then same way i have to count all the lines which is starting from 1 . Then i have to compare with the 7th column of 1st line . It should be same . Here in this file it should be 9.
MY CODE IS :-
Procedure Pay_Simulator(lfile_type varchar2,lac_no varchar2,lcur varchar2,lno_item number,ltotal number,ldate date,lpay_purp varchar2,lfile_name varchar2)
IS
v_handle TEXT_IO.file_type;
v_filebuffer varchar2(500);
line_0_date VARCHAR2 (10);
line_0_Purp VARCHAR2 (10);
line_0_count Number;
line_0_sum number(12,2);
line_0_ccy Varchar2(3);
line_9_sum Number(12,2);
line_9_Acc_no Varchar2(12);
Line_1_Sum Number(12,2);
Line_1_tot Number(15,2) := 0;
Line_1_flag Number := 0;
lval number;
lacno varchar2(16);
v_file varchar2(20);
v_path varchar2(50);
LC$String VARCHAR2(50) ;--:= 'one|two|three|four|five|six|seven' ;
LC$Token VARCHAR2(100) ;
i PLS_INTEGER := 2 ;
lfirst_char number;
lvalue Varchar2(100) ;
Begin
v_file := mcb_simulator_pkg.GET_FILENAME(lfile_name); For the file name
v_path :=rtrim(regexp_substr( lfile_name , '.*\\' ),'\'); For the Path
--v_path := SUBSTR (lfile_name,0, INSTR (lfile_name, '\', -1));
Message(lfile_name);
v_handle := TEXT_IO.fopen(lfile_name, 'r');
BEGIN
LOOP
TEXT_IO.get_line (v_handle, v_filebuffer);
lfirst_char := Substr(v_filebuffer,0,1);
--Message('First Char '||lfirst_char);
IF lfirst_char = '0' Then
Loop
LC$Token := mcb_simulator_pkg.Split( v_filebuffer, i , '|') ;
Message('VAL - '||LC$Token);
lvalue := LC$Token;
EXIT WHEN LC$Token IS NULL ;
i := i + 1 ;
End Loop;
Else
Insert into MU_SIMULATOR_output_ERR (load_no,ERR_CODE,ERR_DESC) values (9999,'0002','First line should always start with 0');
Forms_DDL('Commit');
raise form_Trigger_failure;
End if ;
TEXT_IO.get_line (v_handle, v_filebuffer);
lfirst_char := Substr(v_filebuffer,0,1);
LC$Token := mcb_simulator_pkg.Split( v_filebuffer, i , '|') ;
--Message('Row '||LC$Token);
IF lfirst_char = '9' Then
Null;
Else
Insert into MU_SIMULATOR_output_ERR (load_no,ERR_CODE,ERR_DESC) values (8888,'0016','Second line should start with 9');
Forms_DDL('Commit');
raise form_Trigger_failure;
End IF;
LOOP
TEXT_IO.get_line (v_handle, v_filebuffer);
lfirst_char := Substr(v_filebuffer,0,1);
LC$Token := mcb_simulator_pkg.Split( v_filebuffer, i , '|') ;
--Message('Row '||LC$Token);
IF lfirst_char = '1' Then
Null;
Else
Insert into MU_SIMULATOR_output_ERR (load_no,ERR_CODE,ERR_DESC) values (7777,'0022','The third line onward should start with 1');
Forms_DDL('Commit');
raise form_Trigger_failure;
End if;
END LOOP;
--END IF;
END LOOP;
EXCEPTION
When No_Data_Found Then
TEXT_IO.fclose (v_handle);
END;
Exception
When Others Then
Message('Other error');
END;
I am calling the FUNCTION which you gave SPLIT as mcb_simulator_pkg.Split. -
XI Flat File to JDBC Mapping Error
Hi,
I have been trying to insert some records from a flat file into a sybase database using the FILE adapter (with file content conversion) as a sender and the JDBC adapter as a reciever, but I keep getting mapping errors like:
RuntimeException during appliction Java mapping com/sap/xi/tf/_mm_hh_file__hh_sybase_nombres_</Trace>
<Trace level="1" type="T">com.sap.aii.utilxi.misc.api.BaseRuntimeException: RuntimeException in Message-Mapping transformation: Cannot produce target element /ns0:mt_hh_sybase_nombres/STATEMENTNAME. Check xml instance is valid for source xsd and target-field mapping fulfills requirements of target xsd at com.sap.aii.mappingtool.tf3.AMappingProgram.start
I have read through some blogs and I still can't figure out what is wrong.
Flat pipe separated file:
Hans|Robert|Hahn|Gallegos
Karina|Maria|Cordoba|Gutierrez
Datatype for this file looks like this:
Record 1
Row 1...Unbounded
Nombre 1
SegundoNombre 1
ApPaterno 1
ApMaterno 1
Because the FILE adapter uses Content conversion, the file translates to:
<?xml version="1.0" encoding="utf-8" ?>
<ns:hh_test xmlns:ns="http://me.com">
<Record>
<Row>
<Nombre>Hans</Nombre>
<SegundoNombre>Robert</SegundoNombre>
<ApPaterno>Hahn</ApPaterno>
<ApMaterno>Gallegos</ApMaterno>
</Row>
<Row>
<Nombre>Karina</Nombre>
<SegundoNombre>Maria</SegundoNombre>
<ApPaterno>Cordoba</ApPaterno>
<ApMaterno>Gutierrez</ApMaterno>
</Row>
</Record>
</ns:hh_test>
My database table looks like this:
Nombres
ApPaterno
ApMaterno
Datatype for this table looks like this:
STATEMENTNAME 1..Unbounded
nombres 1
action optional
TABLE 1
access 1
Nombres 1
ApPaterno 1
ApMaterno 1
MAPPINGS as follows:
Record ------> no mapping
Row ------> STATEMENTNAME
Constant ------> action
Constant ------> TABLE
Nombre + SegundoNombre ------> Nombres
ApPaterno ----> ApPaterno
ApMaterno ----> ApMaterno
How do I do the mapping ? I've been through a lot of blogs and threads but I haven't found an example like this, a flat pipe separeted multiline file with records to be inserted in a database.
Message was edited by:
Hans HahnHans,
The error shows you have an error in mapping. Also you have mapped constant for ACTION and TABLE. Here you have to hardcode the value INSERT or UPDATE etc for ACTION and the name of the table for TABLE.
Check this weblog where he has mentioned everything what you are looking for:
/people/sap.user72/blog/2005/06/01/file-to-jdbc-adapter-using-sap-xi-30
Also once when you are done with mapping try to execute it in the test tab of mapping editor.
---Satish -
Cannot connect to database using JDBC
Hello!
I am trying to connect to my local database using this script:
import java.sql.*;
public class test{
public static void main (String[] args){
try
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
Statement StmtPersoane = conn.createStatement();
ResultSet CrsPersoane =StmtPersoane.executeQuery("select p.* from personal p");
int jMarca = 0;
while(CrsPersoane.next()){
jMarca = CrsPersoane.getInt("marca");
System.out.println(jMarca);
CrsPersoane.close();
StmtPersoane.close();
conn.close();
catch(SQLException e)
e.printStackTrace();
}When compiling i am getting this error: Error(7,58): cannot access class oracle.jdbc.driver.OracleDriver; file oracle\jdbc\driver\OracleDriver.class not found
I have set a CLASSPATH enviroment variable with value : D:\oracle10g\product\10.1.0\Db_1\jdbc\lib\ojdbc14.jar
Please provide some hints. Thanks in advace !Problem solved with the connection, but now i'm getting another error when i am trying to parse an error. Here is the code a little bit modified:
import java.sql.*;
import java.text.*;
import java.text.ParseException;
import java.util.*;
public class test{
public static void main (String[] args){
try
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
Statement StmtPersoane;
StmtPersoane = conn.createStatement();
ResultSet CrsPersoane =StmtPersoane.executeQuery("select marca from personal");
int jMarca;
jMarca = 0;
java.util.Date dataJava = new java.text.SimpleDateFormat("dd/mm/yyyy").parse("04/10/2006");
java.sql.Date dataSql = new java.sql.Date(dataJava.getTime());
System.out.println("Data: "+dataSql);
System.out.println("Angajatii sunt:");
while(CrsPersoane.next()){
jMarca = CrsPersoane.getInt("marca");
System.out.println(jMarca);
CrsPersoane.close();
StmtPersoane.close();
conn.close();
catch(SQLException e)
e.printStackTrace();
}The error:
Error(24,81): unreported exception: java.text.ParseException; must be caught or declared to be thrown
Any ideas ?
Maybe you are looking for
-
What setting in Toast for creating a DVD-R master for replication?
I just Downloaded the new Toast 7 Titanium. What setting should I use to burn a DVD-R to send in for replication? Someone else said DVD-ROM UDF There is also a "Make Video DVD from VIDEO_TS folder" Which one?
-
How to create a Folder using a SQL Query?
Hi How can I create a Folder (eg. C:\MyNewFolder) using SQL Query?
-
Hi all, I am doing the scenario of file to idoc in which is it necessary to create RFC destination on both XI side and R/3 side. Clarify the settings required from XI to R/3 .. regards, kumar
-
Multi Language support for KM Content
Hi Experts, We have some folders created in KM and all their display names are in English. Now the client has asked for maintaining multi language names for folders and files in KM. Which means if the logon language of the user is in English then the
-
How can i figure out my security question answers
how can i figure out my security questions answers