dcsimg
<font color=red>Help me to solve these problems</font>
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sabu_vs
Posted On:   Friday, May 24, 2002 04:23 AM

Hi I have 2 questions. 1.I want to insert single quotes in database.When I try to insert this; the progrm shows a syntax error. eg; "insert into mytable values('this is 'a value with single quotes')" Is it posiible to escape the single quotes using escape syntax.If yes how? Is there any other methd to do this? 2.I have a table that contains a unique key[eg name]. If I insert a duplicate key the program shows an error. Is it possible to find the field that violated the unique key constraint.[ inthis eg] thanks very much sabu    More>>

Hi



I have 2 questions.




1.I want to insert single quotes in database.When I try to insert this;

the progrm shows a syntax error.



eg; "insert into mytable values('this is 'a value with single quotes')"



Is it posiible to escape the single quotes using escape syntax.If yes how?

Is there any other methd to do this?




2.I have a table that contains a unique key[eg name].

If I insert a duplicate key the program shows an error.

Is it possible to find the field that violated the unique key constraint.[ inthis eg]




thanks very much



sabu

   <<Less

Re: <font color=red>Help me to solve these problems</font>

Posted By:   Anonymous  
Posted On:   Saturday, May 25, 2002 12:34 AM

1) use PrepareStatement instead of Statement.

2) do a select for that unique key, if there is one, don't insert.

Re: <font color=red>Help me to solve these problems</font>

Posted By:   Steve_Long  
Posted On:   Friday, May 24, 2002 05:14 AM

1. yes, it can be done, but each database has its own method of including special characters in text fields. look in the database vendor's sql manual for the database you are using and you should find your answer. also be aware that you also have to handle the retrieval side (selects) when using such characters.


2. catch the exception from the insert or update statement and print out the values of the unique key fields when the constraint violation occurs.

About | Sitemap | Contact