Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to insert records at run time?

 
Abhimanyus singh
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ...Guys..

As I new to JDBC...and don't know how to insert records in the table through a JDBC program...

Somehow i managed to get a code for inserting records in the table.....

But, my concern is regarding the line....



I just need to understand that , what is the NEED of using too many '+' operators to embrace local variable "str" and "no" ???

regards.


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look into PreparedStatement.
 
Abhimanyus singh
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Look into PreparedStatement.


It would be of great help , if you please...elaborate more regarding the PreparedStatement Interface, and let me know the reason for including so many "+" operators..!!!

Regards...
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even better... there's a professionally-written tutorial about JDBC, and it has a section about PreparedStatement. You can read it here: Lesson: JDBC Basics. Actually there's a lot of useful information in that tutorial, so it might be a good idea for you to work through the whole thing rather than just the PreparedStatement section.
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhimanyus singh wrote:Hi ...Guys..

As I new to JDBC...and don't know how to insert records in the table through a JDBC program...

Somehow i managed to get a code for inserting records in the table.....

But, my concern is regarding the line....



I just need to understand that , what is the NEED of using too many '+' operators to embrace local variable "str" and "no" ???

regards.




are you actually asking why are there the 4 '+' signs in that statement?
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhimanyus singh wrote:
Bear Bibeault wrote:Look into PreparedStatement.


It would be of great help , if you please...elaborate more regarding the PreparedStatement Interface, and let me know the reason for including so many "+" operators..!!!

Regards...

The "+" is nothing to do with JDBC, as it is simply used to concatenate strings together where you combine your literal SQL INSERT with the values in your variables to make one big SQL string. But this is the wrong way to do this anyway, as you should use bind variables here. Follow Paul's suggestion to find out more about using PreparedStatement and learning about JDBC.
 
Abhimanyus singh
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wendy Gibbons wrote:
Abhimanyus singh wrote:Hi ...Guys..

As I new to JDBC...and don't know how to insert records in the table through a JDBC program...

Somehow i managed to get a code for inserting records in the table.....

But, my concern is regarding the line....



I just need to understand that , what is the NEED of using too many '+' operators to embrace local variable "str" and "no" ???

regards.




are you actually asking why are there the 4 '+' signs in that statement?


Yes !!!
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't mean to be rude, but i think starting on jdbc may be a bit running before you can walk.
I am presuming this code is cut and pasted from someone else or somewhere else.

what the '+' signs are doing is adding strings together so

run this little snippet inside a main method



then look at that line in your code again, work out what it is doing.
 
Abhimanyus singh
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wendy Gibbons wrote:I don't mean to be rude, but i think starting on jdbc may be a bit running before you can walk.
I am presuming this code is cut and pasted from someone else or somewhere else.

what the '+' signs are doing is adding strings together so

run this little snippet inside a main method



then look at that line in your code again, work out what it is doing.



Hi..Thank you a Lot!!! I can't believe that, something was being missed out by me!! Though, I knew that SQL accepts single quoted STRINGS, but LATER, I came to know that the TWO + operators ,embracing the string variable, are placed to prepend and append it with single quotes !!!

Thanks again!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic