Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Database access..

  1. #1
    Member
    Join Date
    Dec 2010
    Posts
    69
    My Mood
    Busy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Database access..

    Ok, I have a slight issue, I have the following line of code:
    stmt.executeUpdate("INSERT INTO Customer VALUES (" + FName + "," + LName + "," + Addr + "," + Phone + "," + Email + ")");
    and can't figure out how to get it to correctly pass the variables...mainly the mass amount of quotations is killing me, can any solve the dilemma?


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Database access..

    Use as PreparedStatement.

  3. #3
    Member
    Join Date
    Dec 2010
    Posts
    69
    My Mood
    Busy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Database access..

    How would I go about using that?

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Database access..

    I don't know about you but I would go to the Java API and read about the PreparedStatement class.

  5. #5
    Member
    Join Date
    Dec 2010
    Posts
    69
    My Mood
    Busy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Database access..

    Well after looking it up, looks like that would just complicate things more. I just need to resolve the quotation problem i think

  6. #6
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Database access..

    Seriously dude, if you are going to ask for help don't ignore it. PreparedStatement not only will simplfy things by getting rid of the quotes but it also guards against injection attacks.

  7. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Database access..

    Moved to http://www.javaprogrammingforums.com/jdbc-databases/

    Well after looking it up, looks like that would just complicate things more. I just need to resolve the quotation problem i think
    Recommend you listen to the advice you are given, or at least give it a try...a PreparedStatement will solve your problem rather than complicating it.
    Using Prepared Statements (The Java™ Tutorials > JDBC(TM) Database Access > JDBC Basics)
    Last edited by copeg; March 2nd, 2011 at 10:18 PM.

  8. #8
    Member
    Join Date
    Dec 2010
    Posts
    69
    My Mood
    Busy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Database access..

    I'll change it to a PreparedStatement, no need to get defensive though, if the information it took to convey through 3 of your posts was placed in one post...it would of been more helpful.

Similar Threads

  1. Connecting to Access 2007 Database
    By aussiemcgr in forum JDBC & Databases
    Replies: 12
    Last Post: December 14th, 2010, 04:42 PM
  2. Access database SQL query help
    By mjpam in forum JDBC & Databases
    Replies: 3
    Last Post: September 8th, 2010, 08:48 AM
  3. Replies: 6
    Last Post: August 18th, 2010, 05:41 PM
  4. How can i store ArrayList objects in Access database
    By frankycool in forum JDBC & Databases
    Replies: 0
    Last Post: November 4th, 2009, 12:44 AM
  5. access database connectivity from outside an application
    By suchirag in forum JDBC & Databases
    Replies: 0
    Last Post: October 29th, 2009, 02:03 AM