aspose file tools*
The moose likes JDBC and the fly likes How to insert records at run time? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to insert records at run time?" Watch "How to insert records at run time?" New topic
Author

How to insert records at run time?

Abhimanyus singh
Greenhorn

Joined: Apr 11, 2012
Posts: 27
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

Joined: Jan 10, 2002
Posts: 61419
    
  67

Look into PreparedStatement.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Abhimanyus singh
Greenhorn

Joined: Apr 11, 2012
Posts: 27
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
Bartender

Joined: Oct 14, 2005
Posts: 18655
    
    8

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

Joined: Oct 21, 2008
Posts: 1107

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

Joined: Mar 01, 2009
Posts: 1772
    
  14

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.


No more Blub for me, thank you, Vicar.
Abhimanyus singh
Greenhorn

Joined: Apr 11, 2012
Posts: 27
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

Joined: Oct 21, 2008
Posts: 1107

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

Joined: Apr 11, 2012
Posts: 27
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!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to insert records at run time?