Results 1 to 7 of 7
- 02-15-2010, 01:26 PM #1
Member
- Join Date
- Aug 2009
- Posts
- 21
- Rep Power
- 0
Need Explanation for a Simple Query
Hi everybody.
I was developing a JSP page with a "Registration Form" in it.
Therefore I am supposed to store all the information that user provides into the Database.
I was trying to use "Prepared Statement", but my faculty told to use the following simple query. I used it and it worked. But I didn't understand it's meaning.
Pls explain the following query.
Here varibles are String data types.
insert into <table_name> values (' "+variable1+" ',' "+variable2+" ');
Thanks in advance.
- 02-15-2010, 01:40 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
It means exactly what it says. But I find it hard to believe that "faculty" told you to do something as error-prone, and possibly destructive, as that.
Essentially it is
Java Code:insert into <table> values ('<var1>', '<var2'>)
- 02-15-2010, 01:40 PM #3
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
You need to read a database tutorial that explains SQL queries.
The insert should still have been done using a PreparedStatement.
- 02-15-2010, 01:53 PM #4
Member
- Join Date
- Aug 2009
- Posts
- 21
- Rep Power
- 0
My doubt is why '+' and Double quotes symbols are used?
- 02-15-2010, 02:11 PM #5
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
When using sql, you use ' ' wrapped aroung text for character literals
e.g
The characters need to have the quotes while the integer does not need them.Java Code:insert into users(id,name) values (1, 'vinoth');
When writing the query in java you need to add those quotes too. Read about this in a SQL tutorial.
The + operator just adds the strings together the same way as it does in
OrJava Code:String greetVinoth = "Hello " + "vinoth";
Using the PreparedStatement takes away the need to add the ' ' around characters and this is one of the reasons why it should be prefered.Java Code:String variable= "vinoth"; String greeting = "Hello " + variable;
Last edited by r035198x; 02-15-2010 at 02:15 PM.
- 02-15-2010, 03:37 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
- 02-15-2010, 04:01 PM #7
Member
- Join Date
- Aug 2009
- Posts
- 21
- Rep Power
- 0
Similar Threads
-
explanation of this loop?
By glopez09 in forum New To JavaReplies: 4Last Post: 11-15-2009, 02:36 AM -
the explanation of output of simple java program
By amol84 in forum New To JavaReplies: 1Last Post: 11-06-2008, 05:06 PM -
Class explanation
By mcal in forum New To JavaReplies: 1Last Post: 02-05-2008, 06:50 PM -
need a little explanation
By cew27 in forum New To JavaReplies: 7Last Post: 12-13-2007, 11:39 PM -
I need didactic explanation
By Eric in forum New To JavaReplies: 2Last Post: 07-02-2007, 05:37 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks