Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

prepared statement

Thread view: 
mamta81 - 27 Oct 2007 12:36 GMT
hi all,
i am trying to insert data into a table using preparedStatement
because i have to insert single quote(') in one of the
columns.Whenever i am  a trying to insert a single quote it is not
working though in other columns new data gets inserted.

the query is
sqlQuery="insert into
po_item(po_no,po_item_cd,po_itemdesc,po_item_uom,po_item_unit_cost,po_item_qty,po_item_tax,po_item_dis,po_item_cost,SRL_NO)values
(?,?,?,?,?,?,?,?,?,?)";

desc po_item
Name                           Null
Type
------------------------------ --------
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PO_NO                          NOT NULL
NUMBER(5)
PO_ITEM_CD                     NOT NULL
CHAR(12)
PO_ITEMDESC
VARCHAR2(2000)
PO_ITEM_UNIT_COST
NUMBER(12,2)
PO_ITEM_UOM
CHAR(6)
PO_ITEM_QTY
NUMBER(12,2)
PO_ITEM_COST
NUMBER(12,2)
PO_ITEM_TAX
NUMBER(5)
PO_ITEM_DIS
NUMBER(4,2)
PO_ITEM_RECV_QTY
NUMBER(10)
SRL_NO
NUMBER(2)

db_connection.setPreparedStatement(sqlQuery);
       db_connection.getPreparedStatement().setInt(1,po_no);

db_connection.getPreparedStatement().setString(2,poTable.getValueAt(i,
0).toString().trim());

db_connection.getPreparedStatement().setString(3,poTable.getValueAt(i,
1).toString().trim());

db_connection.getPreparedStatement().setString(4,poTable.getValueAt(i,
2).toString().trim());

db_connection.getPreparedStatement().setDouble(5,Double.parseDouble(poTable.getValueAt(i,
3).toString().trim()));

db_connection.getPreparedStatement().setDouble(6,Double.parseDouble(poTable.getValueAt(i,
4).toString().trim()));

db_connection.getPreparedStatement().setDouble(7,Double.parseDouble(poTable.getValueAt(i,
5).toString().trim()));

db_connection.getPreparedStatement().setDouble(8,Double.parseDouble(poTable.getValueAt(i,
6).toString().trim()));

db_connection.getPreparedStatement().setDouble(9,Double.parseDouble(poTable.getValueAt(i,
7).toString().trim()));
       db_connection.getPreparedStatement().setInt(10,serialNo);

PLS HELP!!!!!!!!!!!!!!!!!
Lew - 27 Oct 2007 14:38 GMT
>  i [sic] am trying to insert data into a table using preparedStatement

Do you mean "PreparedStatement", as in java.sql.PreparedStatement?

Case matters in Java.

> because i [sic] have to insert single quote(') in one of the
> columns.Whenever i [sic] am  a trying to insert a single quote it is not
[quoted text clipped - 15 lines]
> CHAR(12)
> PO_ITEMDESC

What is all this?
Where is the code that tries to insert a single quote?

Could you maybe try formatting your Usenet posts to be actually readable, hmm?

> PLS HELP!!!!!!!!!!!!!!!!!

Lay off the shouting, will you?  It is annoying.

Provide an example that shows what you are doing and where it goes wrong, what
you expect to happen and what's happening instead.  There isn't the
information in what you gave us to allow assistance.

What column are you trying to add a single-quote to?  What data are you
feeding it?

FWIW, it's no problem to insert a single quote into any of the CHARACTER-based
column types using JDBC.

PreparedStatement ps = cxn.prepareStatement( sql );
ps.setString( 1, "'" );

Signature

Lew

Roedy Green - 27 Oct 2007 19:27 GMT
> i am trying to insert data into a table using preparedStatement
>because i have to insert single quote(') in one of the
>columns.Whenever i am  a trying to insert a single quote it is not
>working though in other columns new data gets inserted.

see http://mindprod.com/jgloss/jdbc.html#LITERALS
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.