Insert comand in jdbc
Hello;
Could anyone tell how to use the insert command in jdbc
My code write as following, but it does not work. it complains that i could not use the varible of a, if i write like that (3333, 'ghg','jhjh'), then it work.
String myString="assdsdf";
String strQuery = "INSERT INTO Customer Values " +
"(33333, myString,myString)"; / / how i put a varible of myString here?Thanks
Thanks, but it does not work, and the compiler does not complain anything.
public static Connection con;
try {
//open a connection to the database
c = DriverManager.getConnection( strUrl, strUser, strPass);
catch (SQLException e) {
System.out.println("Cannot connect to the database. Here is the error:");
e.printStackTrace();
System.exit( -1);
try {
//create a statement object to execute sql statements
s = con.createStatement();
String a="trtr";
//our example query
String strQuery = "INSERT INTO Customer Values (?, ?,?,?, ?)";
PreparedStatement pstmt = c.prepareStatement(strQuery);
pstmt.setInt(1, 10909);
pstmt.setString(2, a);
pstmt.setString(3, a);
pstmt.setString(4, a);
pstmt.setString(5, a);
s.close();
catch (SQLException e) {
System.out.println("Something is wrong with your SQL statements. Here is the error:");
e.printStackTrace();
System.exit( -1);
}
Similar Messages
-
Multiple table insert using receiver jdbc adapter
Hi,
I am trying to insert data in to two tables in a single structure using receiver jdbc adapter. I am not using any stored procedure to insert data instead directly inserting the data using PI. Please see the structure I am using.
SOURCE side:
DT_ABC_SENDER
--IT_HEADER_TEXT
-- EBELN
-- LINENO
--TDTEXT
--IT_ITEM_TEXT
-- EBELN
-- LINENO
--TDLINE
TARGET side:
DT_ABC_RECEIVER
--InsertStatement
--HEADER_TEXT
-- action (insert)
-- Table (Table 1)
--access
-- IDS_ENQ_NO
-- IDS_DESC
-- IDS_TEXT
--ITEM_TEXT
-- action (insert)
-- Table (Table 2)
--access
-- IIS_ENQ_NO
-- IIS_DESC
-- IIS_TEXT
Using the above structure I am able to successfully insert the data in Table 1 but data is not getting inserted in Table 2.
In sxmb_moni it is saying message successfully delivered but I but there is data insertion took place in Table 2.
Please help me urgently.
Thanks in advance.
NeeerajHi Neeraj,
Add --InsertStatement statement for the second table structure in the same level of first InsertStatement.
Target structure like this:
DT_ABC_RECEIVER
--InsertStatement
--HEADER_TEXT
-- action (insert)
-- Table (Table 1)
--access
-- IDS_ENQ_NO
-- IDS_DESC
-- IDS_TEXT
--InsertStatement
--ITEM_TEXT
-- action (insert)
-- Table (Table 2)
--access
-- IIS_ENQ_NO
-- IIS_DESC
-- IIS_TEXT -
Query in Insert statement with JDBC Rx adapter
Hi,
This is a FILE to JDBC scenario.
My target datatype is like this with sample payload values
statement_s
statement_s
action='INSERT"
access
A=1234
B=1002
key
A=1234
B ="10%"
compareOperation= LIKE
A(1..1) is primary key in DB and B(0..1) colunm is an optional one.
I want to know if such kind of Insert query with(LIKE operator) is possible.
Please reply me ASAP.
Edited by: ram pranav on Feb 18, 2009 10:28 PMHi Ram,
IN case of "UPDATE_INSERT", you can use the KEY tag in your structure. Also you can provide LIKE as an attribute to the KEY element as follows :
<key1>
<col4 compareOperation=u201DLIKEu201D>val%</col4>
</key1>
But when you are trying to insert the data_, the <key> tags will be ignored and only <access> will be considered._
action=UPDATE_INSERT
The statement has the same format as for the UPDATE action. Initially, the same action is executed as for UPDATE. If no update to the database table can be made for this action (the condition does not apply to any table entry), values of the table described in the <access> element are inserted in accordance with the description of the action INSERT. <key> elements are ignored in this case.
The response document has the following format; one of the two values is always 0 because either an UPDATE or an INSERT action is always executed:
Go through the link I have provided earlier.
Thanks,
Pooja Pandey -
Insert query in JDBC Reciever adapter!!!
Hi All,
We have an interface in which we are inserting data in Oracle server using JDBC Reciever Adapter.
The interface ends up in error on adapter engine level whenever the we are sending long data in one of the field of target structure. The error which we get in communication channel monitoring is that "String too long", on googling i found that in oracle they solve such problem by making the field data type as CLOB.
Thus can we define target structure field of CLOB type so that while inserting the data in Oracle server we never face the issue of this long string.
Thanks>
Arpit Seth wrote:
> Hi All,
>
> We have an interface in which we are inserting data in Oracle server using JDBC Reciever Adapter.
> The interface ends up in error on adapter engine level whenever the we are sending long data in one of the field of target structure. The error which we get in communication channel monitoring is that "String too long", on googling i found that in oracle they solve such problem by making the field data type as CLOB.
>
> Thus can we define target structure field of CLOB type so that while inserting the data in Oracle server we never face the issue of this long string.
>
> Thanks
if the field contains very large data then yes, defining the target field in Oracle as a CLOB will solve your issue.
http://www.herongyang.com/jdbc/MySQL-CLOB-Overview.html -
DB Insert failed through JDBC Adapter
Hi all,
My system is on the latest patches of XI3.0 SP9. I am trying to insert some records into a database through JDBC adapter. The XML arriving at JDBC adapter is:
<?xml version="1.0" encoding="UTF-8" ?>
<ns:MaterialDataUpdate_Msg xmlns:ns="http://acsis.com/ManufacturingManagement">
<MaterialData>
<TMP_MAT_SERIAL action="INSERT">
<table>TMP_MAT_SERIAL</table>
<access>
<MATNO>0000000012</MATNO>
<BATCH>32151</BATCH>
<ITM_SERIAL>453176587769</ITM_SERIAL>
<WEIGHT>12.34</WEIGHT>
<T_TIME>2005-01-21 13:21:34.432</T_TIME>
</access>
</TMP_MAT_SERIAL>
</MaterialData>
</ns:MaterialDataUpdate_Msg>
The connection to the database looks ok. My JDBC adapter config is pointing to "jdbc:microsoft:sqlserver://sapsrv03:1433;databaseName=JDE".
In rwb, I got the following error:
Unable to execute statement for table or stored procedure. "TMP_MAT_SERIAL" due to java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid object name 'TMP_MAT_SERIAL'.
I have checked the database "JDE", and the table 'TMP_MAT_SERIAL' does exist.
Does anyone have any idea about this error?
Thanks a lot for helping!
HartHi Hart Liu,
My system is on the latest patches of XI3.0 SP9. I am trying to insert some records into a database through JDBC adapter.
We have been facing with problem XSD structure in the jdbc side. We r manually created XSD structure. In the adapter engine we dont have any action item. In u r mail
U r structure contains action attribute.
Can u plz help me out to generate the right XSD structure?
We have one more doubt, is there any automatically structure-generated option? plz let us know.......
We r waiting for u r reply....
Plz help me!!!!!!!!
Regards,
Anil -
Insert + Delete in JDBC Reciever/ SOAP Reciever..
Hi,
I have a requirement where I need to send date from SAP to multiple recivers ( DB+ Webservice).
Now based on a field, it will be decided whether it is going to be FULL or Delta update.
In case of
1. Full: All the Db entries should be deleted and then the new records will be inserted.
2. Delta: Only new records will be updated.
Now I want to ask :
1. How can I do this using Db ?
I am aware I can use BPM or multiple MT in the mapping but I want to get detailed explaination about this plan.
2. How can I do this with SOAP adapter.Hi. Why do you wanna use soap? you can do it with jdbc adapter.
1)
check:
http://help.sap.com/saphelp_nw70/helpdata/en/4d/8c103e05df2e4b95cbcc68fed61705/content.htm
you will have to create two statementName nodes, when for insert and one for delete actions.
2)
In case you have to send to multiple receivers based on source message you will have to use enhanced receiver determination. There you can create only one receiver determination, that will decide where to send message. Then you have to create several interface determinations, one for each receiver System.
check:
http://help.sap.com/saphelp_nw70/helpdata/en/43/a5f2066340332de10000000a11466f/frameset.htm
There is much more info in sdn regarding this kind of requirement!
Hope it helps
Regards,
Federico -
How to write sql insert statement if the code is like this:
String Str1 = "abhishek"
String St21 = "Agrawal"
stmt.executeUpdate("insert into my_table values( \"str1\",\"str2\")");
this is not working
help ME!!!!!first if ur using oracle just check the connection is proper or not just print below
S.O.P(1); if it prints ur connection is successful. then dont use ur query write complete column name and then values ();
write ResultSet rs=stmt.executeQuery();
after tht take a while(rs.next())
s.o.p.(rs,getint(1)) 1= columname or " ".
con.close();
Try this. -
How to Insert Date in JDBC?
Hi there,
I'm having problems in inserting a date value in MS Access Database through bridge driver. I parsed the string to date. but that date is java.util.Date not java.sql.Date. hence error comes. if I typecast it, it gives IllegalArgumentException. I'm stumped !
can anyone help??Use a PreparedStatement to do your insert. This will take care of all of your formatting issues; you just need to create an object that is a java.util.Date, java.util.Time, or java.util.Timestamp.
-
Create Insert comand joining variables
Hi, I'm having a problem, I want to create a execute immediate with the following code
The variable v_values as the values that i want to insert in the table, but i need to add the ' in the beggining and in the end ','' because the value of the variable looks like this:
1','1','','10-11-2004
QRY_INS := ('INSERT INTO TABOWN.GFNT02PD_PGMNT VALUES(''' || v_values || ''', '''')');
EXECUTE IMMEDIATE QRY_INS;
when i execute the command the result fo the qry_ins variable is like this:
INSERT INTO TABOWN.GFNT02PD_PGMNT VALUES('1','1',,TO_DATE('10-11-2004', 'DD-MM-YYYY'),'
the problems is because the ') comes down one line and the value for the last column becames too long, i already tries the rtrim but it didn't work.
thanksYep, you don't need dynamic SQL here at all. You're trying to take a shortcut and what you've done is given yourself a massive headache because of single-quote issues, and given your database a headache because of all those literals you're trying to embed in an insert statement.
The right way to handle this is to parse the values into separate variables (or array elements) and supply them as part of a static insert statement.
Here's some code that parses a delimited string into a string array and then uses the values in a static insert statement.
sql>CREATE OR REPLACE package pkg_split
2 is
3 type string_array is table of varchar2(32) index by pls_integer;
4
5 function f_string_table(p_list in varchar2) return string_array;
6 end;
7 /
Package created.
sql>CREATE OR REPLACE package body pkg_split
2 is
3
4 function f_string_table(
5 p_list in varchar2)
6 return string_array
7 is
8 v_string varchar2(256) := p_list || ',';
9 v_pos pls_integer;
10 v_data string_array;
11 begin
12 loop
13 v_pos := instr(v_string, ',');
14 exit when (nvl(v_pos, 0) = 0);
15 v_data(v_data.count + 1) := trim(substr(v_string, 1, v_pos - 1));
16 v_string := substr(v_string, v_pos + 1);
17 end loop;
18 return (v_data);
19 end f_string_table;
20
21 end;
22 /
Package body created.
sql>declare
2 v_list varchar2(256) := 'horse,pig,cow,dog';
3 v_arr pkg_split.string_array;
4 begin
5 v_arr := pkg_split.f_string_table(v_list);
6 insert into t (a, b, c, d) values (v_arr(1), v_arr(2), v_arr(3), v_arr(4));
7 end;
8 /
PL/SQL procedure successfully completed.
sql>select * from t;
A B C D
horse pig cow dog
1 row selected. -
hi i created a ztable and now by using gui_upload i want to enter a flat file to the that database table
now i need to keep 3 radio buttons on the selection screen they are insert modify and delete by using these radio buttons flat file must be upload according to that condition by using GUI_UPLOAD fm
can anyone help how can we solve ithi mahesh
thanks for reply
i already did in the same format what u told
but i am getting dump if possible check the code once and tell me whats the error is
PARAMETERS: FILE LIKE IBIPPARMS-PATH.
DATA: BEGIN OF IT_tmg OCCURS 0,
NAME TYPE ZTMG-NAME,
DOB(10), " TYPE ZTMG-DOB,
GENDER TYPE ZTMG-GENDER,
END OF IT_tmg.
DATA PFILE TYPE STRING.
DATA : WA like ZTMG occurs 0 with header line.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = 'x'
IMPORTING
FILE_NAME = FILE.
PFILE = FILE.
START-OF-SELECTION.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = PFILE
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = IT_tmg
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
ENDIF.
LOOP AT IT.
WRITE:/ IT-NAME.
ENDLOOP.
SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS : INSERT RADIOBUTTON GROUP G1,
MODIFY RADIOBUTTON GROUP G1,
DELETE RADIOBUTTON GROUP G1.
SELECTION-SCREEN : END OF BLOCK B1 .
*MOVE IT TO WA.
WA-NAME = IT_tmg-NAME.
WA-DOB = IT_tmg-DOB.
WA-GENDER = IT_tmg-GENDER.
IF INSERT = 'X'.
*LOOP AT IT.
INSERT ztmg from table wa.
**ENDLOOP.
*MODIFY .
else.
if modify = 'x'.
update ztmg from table wa.
else.
delete ztmg from table wa.
ENDIF.
ENDIF. -
Inserting JTable for JDBC swing project in programme.
i,ve a problem to develop an application contains table area
with fixed columns but multiple rows in it.give me a suitable suggestion plz.http://forum.java.sun.com/thread.jsp?forum=57&thread=271752
Take a look at this thread and please read carefully.
James -
Receiver JDBC: Error while doing the Deleting and Inserting new records
Hi All,
I am doing Idoc to JDBC scenario. In this I am collecting & bundling different type of Idocs and then sending to the JDBC receiver. My requirement is to delete the existing records in the database and insert the new records. I have configures as mentioned in the link
Re: Combining DELETE and INSERT statements in JDBC receiver
In the above link its shows for single mapping. In my scenario I am using multi mapping for collecting idocs in BPM. If I configured for normal mapping then it is working fine(Deleting existing records and Inserting new record). Whenever I am using multi mapping then I am getting following error in the receiver JDBC communication channel u201CError while parsing or executing XML-SQL document: Error processing request in sax parser: No 'action' attribute found in XML document (attribute "action" missing or wrong XML structure)u201D . Can you please tell me what might be the problem.
Thanks & Regards,
T.PurushothamHi !
check this out:
JDBC - No 'action' attribute found in XML document - error
JDBC receiver adapter: No 'action' attribute found in XML document
It appears that the inbound payload (the one that is going from XI to the JDBC adapter) does not have the requiered tag to specify which SQL action to execute in the receiver system. Maybe the multimapping is not creating the desired output message format.
Regards,
Matias. -
JDBC를 이용해서 BLOB COLUMN 에 파일 INSERT하는 SAMPLE
제품 : JAVA
작성날짜 : 2003-01-15
JDBC를 이용해서 BLOB COLUMN 에 파일 INSERT하는 SAMPLE
====================================================
Purpose
JDBC를 이용해서 BLOB COLUMN 에 파일 INSERT하는 방법을
알아 봅니다.
Explanation
- 다음 sample은 Oracle DB v8.1.7에서 JDBC(V8.1.7)을
이용해서 TEST한 것입니다.
Example
import java.sql.*;
import java.io.*;
import java.util.*;
import oracle.jdbc.driver.*;
//needed for new CLOB and BLOB classes
import oracle.sql.*;
public class Insert_File_BLOB
public static void main (String args [])
throws Exception
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn =
DriverManager.getConnection ("jdbc:oracle:oci8:@krint-7", "scott", "tiger");
conn.setAutoCommit (false);
Statement stmt = conn.createStatement ();
// Drop the basic_lob_table
try
stmt.execute ("drop table basic_lob_table");
catch (SQLException e)
// An exception could be raised here if the table did not exist already
// but we gleefully ignore it
// Create a table containing a BLOB and a CLOB
stmt.execute ("create table basic_lob_table (x varchar2 (30), b blob, c clob)");
// Populate the table
stmt.execute ("insert into basic_lob_table values ('one',empty_blob(), 'clob column data !!!')");
// Select the lobs
OracleResultSet rset = (OracleResultSet)stmt.executeQuery("select b from basic_lob_table where x='one' for update");
while (rset.next ())
// Get the lobs
BLOB blob = ((OracleResultSet)rset).getBLOB (1);
try
File file = new File("c:\\temp\\bokim.txt");
long fileLength = (long) file.length();
System.out.println("File Size : " + fileLength + " bytes");
FileInputStream instream = new FileInputStream(file);
OutputStream outstream = blob.getBinaryOutputStream();
int size = blob.getBufferSize();
System.out.println("BufferSize: " + size + " bytes (#)\n");
byte[] buffer = new byte[size];
int length = -1;
while ((length = instream.read(buffer)) != -1)
outstream.write(buffer, 0, length);
System.out.print("#");
System.out.println();
instream.close();
outstream.close();
System.out.println("\nUpdate Done.");
catch (java.io.FileNotFoundException fe) {
System.err.println ("thrown: java.io.FileNotFoundException\n");
fe.printStackTrace ();
System.err.println (fe.getMessage ());
stmt.close();
conn.commit();
conn.close();
결과
SQL> select dbms_lob.getlength(b) from basic_lob_table;
no rows selected
SQL> /
DBMS_LOB.GETLENGTH(B)
4328
Reference Documment
--------------------- -
Data limitation for inserts with JDBC?
I'm having problems with inserting data using JDBC that came with
Oracle 8.1.5. I'm inserting text into a long field. It works
fine until i approach 99K+. The error i'm receiving is
"unimplemented or unreasonable conversion requested". If i
remove some of the text it works fine. Its not the content thats
that causes the problem, but the size. I just inserted a string
of a's until it hit some limit. Is this a known limit? Please
help.
Text added: (99K+ of a's)
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
nullHI Nilesh
This error comes when Xi server is unable to access the Data base server .Please check if port 1433 is open from your Xi server .
Format for Connection string
jdbc:microsoft:sqlserver:,<database path>:1433;DatabaseName=,<dbname>;AuthenticationMethod=type2
Similar problem with solution
Socket Error
Error in JDBC adapter
Cheers..
Vasu
<u>** Reward Points if found useful **</u> -
Calling stored procedure multiple times in the JDBC receiver
Hi,
I am calling the stored procedure(SP) to update a DB table in the JDBC receiver.
SP has 10 input parameters, and SP can receive one value for each parameter at a time.
In my case, i will have multiple rows to insert using SP.i.e multiple values for each parameter.
Its working correctly for a single value for each parameter, but when i have multiple values i want to call the SP multiples times.
Is this possible and how?
Thanks,
Varghese.Varghese,
I think you can have multiple statements in the JDBC Adapter's XML, as in http://help.sap.com/saphelp_nw04/helpdata/en/2e/96fd3f2d14e869e10000000a155106/content.htm.
Here the StatementName1 node can be inserted into your JDBC XML as often as you want.
Kind regards,
Koen
Maybe you are looking for
-
How do I use OS9 apps on my new iMac?
I just got an iMac running 10.6.1 And I still have a Mac Mini running 10.4.11, which allows me to access several apps running under Classic. I'd like to still access them on the glossy new monitor, with the wireless Magic Mouse. I've heard two possib
-
Audio out of sync on source file
So I've captured 4 tapes from an event. The 1st two tapes captured produced a quicktime file with the audio out of sync. The last two tapes are fine. The sample rates match both the capture settings and sequence settings and "make new clip on timecod
-
Hi, Is there any method in APO of smoothing out a supply plan similar to the range of coverage profile in R/3. What we would like is that: APO looks out say 100 days in the future. Adds all demand. Divides by 100 to get an average daily demand. Creat
-
How do I set a locked size on a frame.
say i want to set the frame to be a size where even if i minimize it or not, the data inside it will not move about. It will stay exact. Like say for example i minimize this html website it goes smaller but the data does not move about when minimized
-
Where or how to download JRE version 5 update 23 or higher?
Seeing that this is a Sun forum devoted to the Java JRE, there must be people here that can answer these questions: a) why are there updates to Version 5 higher than update 22 being developed but not being made publically available? b) what is the lo