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 2 of 2

Thread: Passing data to a MySQL database

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Passing data to a MySQL database

    Hi I'm having a little trouble passing a few variablesin to a database using a java servlet, here is the code I am working with and what I have attempted so far...

    String ID = request.getParameter("ID"); 
    	String name = request.getParameter("name");
    	String surname = request.getParameter("surname");
    	String degree = request.getParameter("degree");
    	String DOB = request.getParameter("DOB");

    These are my variables which pulled form another HTML form

    I want to pass these into a table 'students' which is already created.

    the trouble I am having is concatenating the statement so it will work through Mysql, I am sure it is very simple but I just can't figure it out.

    This is what I have tried so far

    String updateSQL = "insert into students (studentno, firstname, surname, degreecode, dob) values '" + ID + "',"+"'" + name + ",'"+"'" + surname + ",'"+"'" + degree + ",'"+"'" + DOB + "'}";

    Thanks in advance for any help!


  2. #2
    Junior Member
    Join Date
    Dec 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Passing data to a MySQL database

    Nevermind, sorted it out

    this is the code if anyone is interested...
    String updateSQL = "insert into students (studentno, firstname, surname, degreecode, dob) values  ('" + ID + "',"+"'" + name + "',"+"'" + surname + "', "+"'" + degree + "' ,"+"'" + DOB + "')";

Similar Threads

  1. Checking an online MySQL Database
    By Aaron in forum Java Theory & Questions
    Replies: 1
    Last Post: November 25th, 2010, 03:32 PM
  2. MySQL Database
    By pjeremy90 in forum Java Theory & Questions
    Replies: 2
    Last Post: June 12th, 2010, 10:34 AM
  3. [SOLVED] Get Data From Database MySQL using ComboBox
    By Simple in forum Java Theory & Questions
    Replies: 2
    Last Post: June 4th, 2010, 02:45 AM
  4. Download File from Mysql database
    By Puk284 in forum Java Servlet
    Replies: 0
    Last Post: April 24th, 2010, 07:43 AM
  5. problems with connection to mysql database
    By thepower in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 20th, 2010, 02:59 AM