Setting priority of order of DELETE -vs- INSERT commands in Oracle database
Hi,
I have an .NET application which has a DELETE command (e.g. Delele from MyTable where id = 1) immediately followed by an INSERT command (e.g. INSERT INTO MyTable (id, field1, field2) values (1, 'x', 'y').
We are not using transactions, so the commands are independent.
MyTable has a unique constraint on the id column.
On occasion, I am getting an error "ORA-00001 : unique constraint ... violated."
I speculate that the INSERT command is being processed by the database before the DELETE command.
Would you know if the priority of INSERT commands can be set higher to DELETE commands? How could I set this on my database (for testing purposes)?
Thanks!
One piece of the puzzle that I nelgected to mention...
This DELETE/INSERT scenario is happening in an ASP.NET application going through Oracle's .NET driver (ODP.NET).
The DELETE and INSERT are run with the autocommit feature of ODP.NET (I assume this translates into a separate transaction for each of these two statements).
We have the "connection pooling" enabled (for the ODP.NET). Maybe because of the connection pooling, might ODP.NET be reversing the order of the DELETE and UPDATE commands?
A problem I have is that I cannot see this problem occur on my server: the problem only occurs on the customer's server. He has reported several occurances of the problem.
Do you think the Oracle session tracing will be of help if I cannot reproduce the problem (on my machine)?
Thanks for you help so far!
(clarification: The DELETE is run and "auto-committed", the immediately, the INSERT is run and "auto-committed")
Edited by: user8267059 on Oct 15, 2008 6:00 AM
Similar Messages
-
Inserting data in oracle database using ASP.
hi all.
i am using oracle database 11g R2,windows xp,ASP.
i am able to store texts and numbers but i am not able to store image in blob.
here is my table structure.
Roll number
Name varchar2(20)
Subject varchar2(20)
Marks number
Attach Blobmy problem is in blob i am not able to insert image into database using ASP codes.
here is the code.
<%
Dim conn,recset
set conn=server.CreateObject("ADODB.connection")
set recset=server.CreateObject("ADODB.recordset")
'set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="MSDAORA;Data Source=orcl;User ID=XXXX;Password=XXX"
conn.Open(conn)
Dim r,n,s,m,att
r=upload.Form("roll")
n=upload.Form("nam")
s=upload.Form("sub")
m=upload.Form("mark")
att=upload.Form("FILE1")
Response.Write "Succssfully Inserted"
conn.execute "insert into table1 values('"&r&"','"&n&"','"&s&"','"&m&"','"&file1&"')"
conn.close
%>plz guide me and help me out.
thanks in advance..Azure Stream Analytics does not have Boolean type. On input we will convert JSON Boolean value to bigint.
Here is the list of supported types and conversions:
https://msdn.microsoft.com/en-us/library/azure/dn835065.aspx
You can fix this erro by changing column type from bit to int in SQL table schema. -
Insert data into oracle database using a PHP form
I'm trying to enter data into my oracle database table using a php form. When I click submit no data is added. Could someone help me please. I'm new to php/oracle thing.
NOTE: I don't have any problem connecting to the database using php.
Here is the code I'm using:
<?php
// just print form asking for name if none was entered
if( !isset($query)) {
echo "<form action=\"$uri\" method=post>\n";
echo "<p>Enter Name: ";
echo "<input type=text size=100 maxlength=200 name=data value=\"$data\">\n";
echo "<br><input type=submit name=submit value=Submit>\n";
echo "</form>\n";
exit;
// insert client's name
$query = "INSERT INTO client (name) VALUES ($data)";
// connect to Oracle
$username = "xxxx";
$paswd = "yyyyyy";
$dbstring = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)".
"(HOST=patriot.gmu.edu)(PORT=1521))".
"(CONNECT_DATA=(SID=COSC)))";
$db_conn = ocilogon($username, $paswd, $dbstring);
$stmt = OCIParse($db_conn, $query);
OCIExecute($stmt, OCI_DEFAULT);
OCIFreeStatement($stmt);
OCILogoff($db_conn);
?>
Thanks for your help. I will also appreciate a better was to do it.
Tonyresumption and jer,
Sorry I cannot format the code for easy reading!
The page is submitting to itself. See action = \"$uri\". I used the same logic to enter SELECT querries into the database. It pulls and displays data back on the webpage. The code I used for this is below. Compare it with the one above for inserting data into the table.
<?php
// connect to oracle
$username = "xxxxx";
$paswd = "yyyyy";
$dbstring = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)".
"(HOST=patriot.gmu.edu)(PORT=1521))".
"(CONNECT_DATA=(SID=COSC)))";
$db_conn = ocilogon($username, $paswd, $dbstring);
// username and password will be unset if they weren't passed,
// or if they were wrong
if( !isset($query)) {
// just print form asking for account details
echo "<form action=\"$uri\" method=post>\n";
echo "<p>Enter Query: ";
echo "<input type=text size=100 maxlength=200 name=query value=\"$query\">\n";
echo "<br><input type=submit name=submit value=Submit>\n";
echo "</form>\n";
exit;
// remove unwanted slashes from the query
$query = stripslashes($query);
// run the query
$stmt = OCIParse($db_conn, $query);
OCIExecute($stmt, OCI_DEFAULT);
// Open the HTML table.
print '<table border="1" cellspacing="0" cellpadding="3">';
// Read fetched headers.
print '<tr>';
for ($i = 1;$i <= ocinumcols($stmt);$i++)
print '<td class="e">'.ocicolumnname($stmt,$i).'</td>';
print '</tr>';
// Read fetched data.
while (ocifetch($stmt))
// Print open and close HTML row tags and columns data.
print '<tr>';
for ($i = 1;$i <= ocinumcols($stmt);$i++)
print '<td class="v">'.ociresult($stmt,$i).'</td>';
print '</tr>';
// Close the HTML table.
print '</table>';
OCIFreeStatement($stmt);
OCILogoff($db_conn);
?> -
Unable to insert rows into ORACLE database using ABAP code
Hai,
I am facing problem while creating a table in Oracle database with 15 attributes in a table. To create a table I am using the classes:
cl_sql_connection -
> to create the connection
cl_sql_statement -
> to execute the query
This I used by reffering the SAP program ADBC_DEMO. Without any trouble I am able to create a Table with 6 attributes by following the same procedure in ABCD_DEMO program but the same is not working for the table with 15 attributes .
Please help me.
Regards,
SwethaHai,
here is my code.
DATA: V_con_name TYPE dbcon-con_name,
con_ref TYPE REF TO cl_sql_connection,
sqlerr_ref TYPE REF TO cx_sql_exception,
c_tabname TYPE string VALUE `TO_DETAILS`,
c_coldefs TYPE string.
DATA: IT_ORA LIKE ZVOP_X_ORA_UPDATE OCCURS 0 WITH HEADER LINE.
V_CON_NAME = 'TVL-DSS-01'.
concatenate '(LGNUM CHAR(3) primary key,'
'TANUM VARCHAR2(10),'
'FLAG CHAR(1),'
'BDATU timestamp(3),'
'TAPOS VARCHAR2(4),'
'MATNR CHAR(18))'
'VLQNR VARCHAR2(10),'
'VLPLA CHAR(10),'
'VLBER CHAR(3),'
'NLPLA CHAR(10),'
'NLBER CHAR(3),'
'VDATE DATE(3) ,'
'BNAME CHAR(12),'
'VTIME DATE(4),'
'PROTYPEFLAG CHAR(1),'
'PROCOMFLAG CHAR(1))'
into c_coldefs separated by space .
TRY.
PERFORM: CONNECT USING V_CON_NAME CON_REF,
CREATE_TABLE USING con_ref c_tabname c_coldefs.
CATCH cx_sql_exception INTO sqlerr_ref.
TB_ERROR-MESSAGE = SQLERR_REF->SQL_MESSAGE.
APPEND TB_ERROR. CLEAR TB_ERROR.
ENDTRY.
form create
form CONNECT using p_con_name TYPE dbcon-con_name
p_con_ref TYPE REF TO cl_sql_connection
RAISING cx_sql_exception.
p_con_ref = cl_sql_connection=>get_connection( p_con_name ).
endform. " CONNECT
form create
form CREATE_TABLE USING p_con_ref TYPE REF TO cl_sql_connection
p_tabname TYPE string
p_coldefs TYPE string
RAISING cx_sql_exception.
DATA:
l_sqlerr_ref TYPE REF TO cx_sql_exception,
l_stmt TYPE string,
l_stmt_ref TYPE REF TO cl_sql_statement.
create a statement object
l_stmt_ref = p_con_ref->create_statement( ).
create the statement string
CONCATENATE
'create table' p_tabname p_coldefs
INTO l_stmt SEPARATED BY space.
execute the DDL command; catch the exception in order to handle the
case if the table already exists
TRY.
l_stmt_ref->execute_ddl( l_stmt ).
CATCH cx_sql_exception INTO l_sqlerr_ref.
IF l_sqlerr_ref->dbobject_exists = 'X'
OR l_sqlerr_ref->internal_error = 1024.
table already exists => drop it and try it again
PERFORM:
drop_table USING p_con_ref p_tabname,
create_table USING p_con_ref p_tabname p_coldefs.
ELSE.
RAISE EXCEPTION l_sqlerr_ref.
ENDIF.
ENDTRY.
endform. " CREATE_TABLE
please do help me
Regards,
Swetha -
How to insert date into oracle database
Hi, there,
I want to insert date information to oracle database in a jsp page using JSTL. but always got wrong message:
javax.servlet.jsp.JspException:
INSERT INTO DATE_TEST
(date_default,date_short,date_medium)
values(?,?,?)
: Invalid column type
I don't know how to convert java date type to oracle date type or vice versa. the following is the source code(all the fields of DATE_DEFAULT,DATE_SHORT,DATE_MEDIUM are oracle date type. and even I want to insert d instead d1, I got the same wrong message)
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ page import="java.util.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%
Calendar now;
Calendar rightNow = Calendar.getInstance();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>
Hello World
</title>
</head>
<body>
<h2>
The current time is:
</h2>
<p>
<%= new java.util.Date() %></p>
<%
java.util.Date d=new java.util.Date();
java.sql.Date d1=new java.sql.Date(d.getYear(),d.getMonth(),d.getDate());
out.print(d1.toString());
%>
<sql:update>
INSERT INTO DATE_TEST
(DATE_DEFAULT,DATE_SHORT,DATE_MEDIUM)
VALUES(?,?,?)
<sql:dateParam value="${d}" type="date" />
<sql:dateParam value="${d}" type="date" />
<sql:dateParam value="${d}" type="date" />
</sql:update>
</body>
</html>
thank you very much for the great help!!Hi, there,
I want to insert date information to oracle database in a jsp page using JSTL. but always got wrong message:
javax.servlet.jsp.JspException:
INSERT INTO DATE_TEST
(date_default,date_short,date_medium)
values(?,?,?)
: Invalid column type
I don't know how to convert java date type to oracle date type or vice versa. the following is the source code(all the fields of DATE_DEFAULT,DATE_SHORT,DATE_MEDIUM are oracle date type. and even I want to insert d instead d1, I got the same wrong message)
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ page import="java.util.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%
Calendar now;
Calendar rightNow = Calendar.getInstance();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>
Hello World
</title>
</head>
<body>
<h2>
The current time is:
</h2>
<p>
<%= new java.util.Date() %></p>
<%
java.util.Date d=new java.util.Date();
java.sql.Date d1=new java.sql.Date(d.getYear(),d.getMonth(),d.getDate());
out.print(d1.toString());
%>
<sql:update>
INSERT INTO DATE_TEST
(DATE_DEFAULT,DATE_SHORT,DATE_MEDIUM)
VALUES(?,?,?)
<sql:dateParam value="${d}" type="date" />
<sql:dateParam value="${d}" type="date" />
<sql:dateParam value="${d}" type="date" />
</sql:update>
</body>
</html>
thank you very much for the great help!! -
Native SQL: insert data into oracle database, no return message.
hi,
the statement : insert into <TableName> values (Source)
how can I know if the data have already insert to the database table?
now I have a program have this problem: the data has already exist, but there's no error message return when insert the same data again.
data: dbs like dbcon-con_name value 'HRGK',
dbtype type dbcon_dbms.
data: sqlerr_ref type ref to cx_sql_exception,
exc_ref type ref to cx_sy_native_sql_error,
error_text type string.
data: cnt type i,
i(2) type c.
set locale language 'E'.
EXEC SQL.
CONNECT TO :DBS
ENDEXEC.
EXEC SQL.
SET CONNECTION :DBS
ENDEXEC.
EXEC SQL.
SELECT COUNT(*) from org_unit into :cnt
ENDEXEC.
write: / cnt.
*do.
i = 'A'.
try.
EXEC SQL.
BEGIN
insert into ORG_UNIT ( ORGAN_ID, UNIT_NO, UNIT_NAME, PARENT_ID)
values ( 'A', '123412', 'SDFSG', 'DDS'); " ORGAN_ID is primary key
" If the data 'A' has already exist in database ORG_UNIT, it will show error message
" But if I use :I instead 'A', it will not show error message.
IF SQL%FOUND THEN
COMMIT;
END IF;
END;
endexec.
EXEC SQL.
SELECT COUNT(*) from ORG_UNIT into :cnt
ENDEXEC.
write: / cnt.
catch cx_sy_native_sql_error into exc_ref.
error_text = exc_ref->get_text( ).
write: / error_text.
catch cx_sql_exception into sqlerr_ref.
perform handle_sql_exception using sqlerr_ref.
endtry.
EXEC SQL.
disconnect :DBS
ENDEXEC.
*enddo.
*& Form handle_sql_exception
form handle_sql_exception
using p_sqlerr_ref type ref to cx_sql_exception.
format color col_negative.
if p_sqlerr_ref->db_error = 'X'.
write: / 'SQL error occured:', p_sqlerr_ref->sql_code,
/ p_sqlerr_ref->sql_message. "#EC NOTEXT
else.
write:
/ 'Error from DBI (details in dev-trace):',
p_sqlerr_ref->internal_error. "#EC NOTEXT
endif.
endform. "handle_sql_exception
please help to see the words:
*" If the data 'A' has already exist in database ORG_UNIT, it will show error message*
*" But if I use :I instead 'A', it will not show error message.*
in the program.
Thanks a lot!resumption and jer,
Sorry I cannot format the code for easy reading!
The page is submitting to itself. See action = \"$uri\". I used the same logic to enter SELECT querries into the database. It pulls and displays data back on the webpage. The code I used for this is below. Compare it with the one above for inserting data into the table.
<?php
// connect to oracle
$username = "xxxxx";
$paswd = "yyyyy";
$dbstring = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)".
"(HOST=patriot.gmu.edu)(PORT=1521))".
"(CONNECT_DATA=(SID=COSC)))";
$db_conn = ocilogon($username, $paswd, $dbstring);
// username and password will be unset if they weren't passed,
// or if they were wrong
if( !isset($query)) {
// just print form asking for account details
echo "<form action=\"$uri\" method=post>\n";
echo "<p>Enter Query: ";
echo "<input type=text size=100 maxlength=200 name=query value=\"$query\">\n";
echo "<br><input type=submit name=submit value=Submit>\n";
echo "</form>\n";
exit;
// remove unwanted slashes from the query
$query = stripslashes($query);
// run the query
$stmt = OCIParse($db_conn, $query);
OCIExecute($stmt, OCI_DEFAULT);
// Open the HTML table.
print '<table border="1" cellspacing="0" cellpadding="3">';
// Read fetched headers.
print '<tr>';
for ($i = 1;$i <= ocinumcols($stmt);$i++)
print '<td class="e">'.ocicolumnname($stmt,$i).'</td>';
print '</tr>';
// Read fetched data.
while (ocifetch($stmt))
// Print open and close HTML row tags and columns data.
print '<tr>';
for ($i = 1;$i <= ocinumcols($stmt);$i++)
print '<td class="v">'.ociresult($stmt,$i).'</td>';
print '</tr>';
// Close the HTML table.
print '</table>';
OCIFreeStatement($stmt);
OCILogoff($db_conn);
?> -
I receive error when I try to insert Image to Oracle Database v.9i
My Error is :
java.sql.SQLException: ORA-00600: internal error code, arguments: [ttcgcshnd-1], [0], [], [], [], []
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:114)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:542)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1311)
at oracle.jdbc.ttc7TTC7Protocol.fetch(TTC7Protocol.java:797)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:1608)
at oracle.jdbc.driver.OracleStatement.doExecute(OracleStatement..java:1758)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1805)
at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:410)
and my code is:
URL url = null;
InputStream in = null;
Statement stmt = null;
OutputStream out = null;
try {
url = new URL("file://D:/MyJava~1/classes/javalogo.gif");
in = url.openStream();
stmt = con.createStatement();
// Create the table
stmt.execute ("create table ImageTable (count varchar2(20), image BLOB)");
System.out.println("Table created ...");
// create a blob entry in the table
stmt.execute("insert into ImageTable values ('two', empty_blob())");
stmt.execute("commit");
String cmd = "select image from ImageTable for update";
/* error this command/*
ResultSet rset = stmt.executeQuery(cmd);
System.out.println("Success execute command.");
while (rset.next()) {
//get the Blob locator
blob = ((OracleResultSet)rset).getBLOB(1);
System.out.println("Get the BLOB locator");
//get ready to accept binary file
out = blob.getBinaryOutputStream();
int chunk = blob.getChunkSize();
System.out.print("The chunk size is " + chunk);
byte buffer[]= new byte[chunk];
int length;
while ((length = in.read(buffer)) != -1) {
out.write(buffer, 0, length); //image file saved.
con.close();
out.close();
stmt.close();
thank you for your kind
You should try using PreparedStatement instead of Statement while inserting the image - one of the methods like setBytes(. .), setBlob() or setBinaryStatement() of the PreparedStatement should do the trick..
The setBytes( ) is inefficient in terms of memory -esp for large images -better is to use setBinaryStream( ).
Shantanu -
Use scanner or/and camera to insert image into oracle database BLOB feild
can any body show how i can do these? send me an example to do this?
notice: i'am using oracle form 6i & oracle databse 10g
best regards
hamdan
Edited by: user633386 on 05/07/2011 11:57 مIt's been discussed now and then. Hope this helps:
Insert Picture (image) using oracle forms
Looks like a keyword to search on is read_image_file
This all assumes that we know the name of the file. -
Query to insert file in Oracle database 9.2.0.1.0
how can I can reafear to a file field of an oracle database 9.2.0.1.0 in a query?
ThanksHi
Use external table definiton.
Ott Karesz
http://www.trendo-kft.hu -
Re: Insert data into oracle database using a PHP form
Hai its different for me, i want to display a data based on the input from php form. I see and trying your script but it didn't work.
<?php
// just print form asking for name if none was entered
if( !isset($query)) {
echo "<form action=\"$uri\" method=post>\n";
echo "<p>Enter Name: ";
echo "<input type=text size=100 maxlength=200 name=data value=\"$data\">\n";
echo "<br><input type=submit name=submit value=Submit>\n";
echo "</form>\n";
exit;
$data=$_POST;
stripslashes($data);
// Select statement
$query = "SELECT * FROM animal WHERE skin=$data";
// connect to Oracle
$username = "xxxxxx";
$paswd = "xxxxxx";
$dbstring = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)".
"(HOST=yyyyyyyy)(PORT=1521))".
"(CONNECT_DATA=(SID=COSC)))";
$db_conn = ocilogon($username, $paswd, $dbstring);
//$stmt = OCIParse($db_conn, $query);
//OCIExecute($stmt, OCI_DEFAULT);
//OCIFreeStatement($stmt);
//OCILogoff($db_conn);
$stmt = OCIParse ($db_conn, $sql);
OCIBindByName ($stmt, ":name", &$data, -1);
OCIExecute ($stmt);
OCIFreeStatement($stmt);
OCILogoff ($db_conn);
?>
Could you please advice me ? whats wrong with that script ?What is the error you get? What solutions have you tried already?
-
Data insert in SQL & ORACLE databases
Hi
We are sending vendor master data from SAP to SQL & ORACLE database .
It is working successfully for SQL.
we have deployed oracle drivers, completed the configuration part.
When idoc is triggered in SAP,data is uploaded in SQL successfully....but it is showing the following error for Oracle....
....." Unable to execute statement for table or stored procedure. 'tblVendorAddress' (Structure 'Table') due to java.sql.SQLException: FATAL ERROR: Column 'cVendorCode' does not exist in table 'tblVendorAddress' "......
cVendorCode in SQL is defined as cVendorCode ... but in Oracle it is defined as CVENDORCODE...
If i change the datatype in XI as CVENDORCODE...my SQL scenario will not work(cVendorCode)..
I don't want to change my XI datatype structure....records should be updated in SQL & Oracle datadase at the same time.
Please suggest a solution..
Regards
AbhijitHi!
As far as I know this is the only way, because the PI works like all Java based systems (and unix systems) case-sensitive.
But maybe there is a "Wizard" in this forum who knows another way
Regards,
Volker -
Oracle Database Character set and DRM
Hi,
I see the below context in the Hyperion EPM Installation document.
We need to install only Hyperion DRM and not the entire Hyperion product suite, Do we really have to create the database in one of the uft-8 character set?
Why it is saying that we must create the database this way?
Any help is appreciated.
Oracle Database Creation Considerations:
The database must be created using Unicode Transformation Format UTF-8 encoding
(character set). Oracle supports the following character sets with UTF-8 encoding:
l AL32UTF8 (UTF-8 encoding for ASCII platforms)
l UTF8 (backward-compatible encoding for Oracle)
l UTFE (UTF-8 encoding for EBCDIC platforms)
Note: The UTF-8 character set must be applied to the client and to the Oracle database.
Edited by: 851266 on Apr 11, 2011 12:01 AMSrini,
Thanks for your reply.
I would assume that the ConvertToClob function would understand the byte order mark for UTF-8 in the blob and not include any parts of it in the clob. The byte order mark for UTF-8 consists of the byte sequence EF BB BF. The last byte BF corresponds to the upside down question mark '¿' in ISO-8859-1. Too me, it seems as if ConvertToClob is not converting correctly.
Am I missing something?
BTW, the database version is 10.2.0.3 on Solaris 10 x86_64
Kind Regards,
Eyðun
Edited by: Eyðun E. Jacobsen on Apr 24, 2009 8:26 PM -
Insert into Oracle Database using C#
Hi Everyone,
I am trying to take data from text box and list box and then insert them to Oracle database:
Text box data:
Oracle = EMPLOYEE_NAME
C# = tbEmployeeName
List box data:
Oracle = EMPLOYEE_GENDER
C# = lbEmployeeGender
Here is my code in C#, can you guys help me with insert statement:
string oradb = "Data Source= oraDB;User Id=sm;Password=mypassword;";
OracleConnection conn = new OracleConnection(oradb);
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "Insert into USER.EMPLOYEE VALUES (tbEmployeeName.Text, lbEmployeeGender.Text)";
int rowsUpdated = cmd.ExecuteNonQuery();
if (rowsUpdated == 0)
MessageBox.Show("Record not inserted");
else
MessageBox.Show("Success!");
conn.Dispose();
Thanks!989630 wrote:
Hi Everyone,
I am trying to take data from text box and list box and then insert them to Oracle database:
Text box data:
Oracle = EMPLOYEE_NAME
C# = tbEmployeeName
List box data:
Oracle = EMPLOYEE_GENDER
C# = lbEmployeeGender
Here is my code in C#, can you guys help me with insert statement:
string oradb = "Data Source= oraDB;User Id=sm;Password=mypassword;";
OracleConnection conn = new OracleConnection(oradb);
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "Insert into USER.EMPLOYEE VALUES (tbEmployeeName.Text, lbEmployeeGender.Text)";
int rowsUpdated = cmd.ExecuteNonQuery();
if (rowsUpdated == 0)
MessageBox.Show("Record not inserted");
else
MessageBox.Show("Success!");
conn.Dispose();
Thanks!Hi,
You'll want to read up on using parameters (also known as bind variables) - these are critical for scalability in an OLTP-type system and helping guard against SQL Injection attacks. There's many sources out there, but here's a link to the Parameter Binding section in the ODP.NET Developer's Guide which is probably a good thing to become familiar with:
http://docs.oracle.com/cd/E11882_01/win.112/e23174/featOraCommand.htm#i1007242
Here's your sample using bind variables:
string oradb = "Data Source= oraDB;User Id=sm;Password=mypassword;";
OracleConnection conn = new OracleConnection(oradb);
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
// Perform insert using parameters (bind variables)
cmd.CommandText = "Insert into USER.EMPLOYEE VALUES (:1, :2)";
// Here's one way to use parameters aka bind variables:
// Create parameters to hold values from front-end
cmd.Parameters.Add(new OracleParameter("1",
OracleDbType.Varchar2,
tbEmployeeName.Text,
ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("2",
OracleDbType.Varchar2,
lbEmployeeGender.Text,
ParameterDirection.Input));
int rowsUpdated = cmd.ExecuteNonQuery();
if (rowsUpdated == 0)
MessageBox.Show("Record not inserted");
else
MessageBox.Show("Success!");
conn.Dispose();
// don't forget to perform any clean-up as necessaryNote that I've just typed this into a text editor and not verified, so please excuse any typos you may find.
Also, I've allowed the default of OracleCommand.BindByName=false as I prefer that, though others certainly prefer setting it to "true". See the docs for what this means if you are not sure.
Regards,
Mark -
How to insert images into oracle databse......
hi,
i have to insert images into oracle database..
but we have a procedure to insert images into oracle database..
how to execute procedure.
my images file is on desktop.
i am using ubuntu linux 8.04..
here i am attaching code of my procedure
create or replace PROCEDURE INSERT_BLOB(filE_namE IN VARCHAR2,dir_name varchar2)
IS
tmp number;
f_lob bfile;
b_lob blob;
BEGIN
dbms_output.put_line('INSERT BLOB Program Starts');
dbms_output.put_line('--------------------------');
dbms_output.put_line('File Name :'||filE_namE);
dbms_output.put_line('--------------------------');
UPDATE photograph SET image=empty_blob()
WHERE file_name =filE_namE
returning image INTO b_lob;
f_lob := bfilename( 'BIS_IMAGE_WORKSPACE',filE_namE);
dbms_lob.fileopen(f_lob,dbms_lob.file_readonly);
--dbms_lob.loadfromfile(b_lob,f_lob,dbms_lob.getlength(f_lob));
insert into photograph values (111,user,sysdate,b_lob);
dbms_lob.fileclose(f_lob);
dbms_output.put_line('BLOB Successfully Inserted');
dbms_output.put_line('--------------------------');
commit;
dbms_output.put_line('File length is: '||dbms_lob.getlength( f_lob));
dbms_output.put_line('Loaded length is: '||dbms_lob.getlength(b_lob));
dbms_output.put_line('BLOB Committed.Program Ends');
dbms_output.put_line('--------------------------');
END inserT_bloB;
warm regerds
pydiraju
please solve my problem
thanks in advance.......thank you
but i am getting the following errors.
i connected as dba and created directory on /home/pydiraju/Desktop/PHOTO_DIR'
and i gave all permissions to scott user.
but it not working . it gives following errors.
ERROR at line 1:
ORA-22288: file or LOB operation FILEOPEN failed
Permission denied
ORA-06512: at "SYS.DBMS_LOB", line 523
ORA-06512: at "SCOTT.LOAD_FILE", line 28
ORA-06512: at line 1
Warm regards,
Pydiraju.P
Mobile: +91 - 9912380544 -
Can't Delete Oracle Database Job
i created an oracle database job and some of them is only a sample test job. i need to delete them but the delete option is not enabled. it looks like all the other oracle database job that i created can't be deleted. please advise thanks.
it does not have. i guess a dependencies should not cause the problem because other jobs that does have dependencies can be deleted. it is only the oracle database job that can't be deleted. thanks.
Maybe you are looking for
-
Converting Open Sales Orders after MM data changes
Hello, We are 'upgrading' a live v4.7 system to now use MRP. We have many open Contracts/Sales Orders with the affected materials. We are looking for a way to have SAP 'recalculate' or 'reload' the material master and VC data for these open orders
-
Chart series should display center of the x-axis lines
Hi, I am using StackedColumn chart in my application and i want the series should be display center of the x-axis. Currently its displaying on the x-axis line. Thanks
-
COMMPR01 - relationship assigment tab is missing
Hello experts, I'm working with CRM 4.0 and I have some problems with the product category customization. I added new type sets to a product category hierarchy and now they are shown correctly in commpr01 transaction, but unfortunately Iu2019m not ab
-
Logical Data base MSM vs Material master table MARA/MARC
Hi Experts, What is the different between the logical data base (LDB) and the normal SAP table, for example MSM vs MARA/MARC/MBEW table. ? I mean we usually refer data to the normal SAP table in download or ABAP, what is the use of logical data base
-
Firefox won't recognize hyperlinks in PeoplePC Webmail message text
When I paste or type in a hyperlink in the body of an email, Internet Explorer recognizes it, and it arrives at the receiver's computer as a hyperlink, which he or she can click on to bring up the web page. With Firefox, it just arrives as text, and