Hi all,

On compiling, i get no errors at all, the data is taken, but when checking the database, a record is made, but it is NULL.

What have i missed?

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package week7;

//declare package

import java.util.Scanner;
import java.sql.*;

public class PersonalDriver
{
	public static void main (String []arguments)
	{


            Scanner myScanner = new Scanner( System.in );
       System.out.println("Please enter first name:");
       String forename = myScanner.nextLine();

        System.out.println("Please enter your surname: ");
        String surname = myScanner.nextLine();

        System.out.println("Please enter your date of birth (DDMMYYYY): ");
        int dob = myScanner.nextInt();

        System.out.println("Please enter the 1st line of your address: ");
        String add1 = myScanner.nextLine();

        System.out.println("Please enter the 2nd line of your address: ");
        String add2 = myScanner.nextLine();

        System.out.println("Please enter your county ");
        String county = myScanner.nextLine();

        System.out.println("Please enter your post code: ");
        String postCode = myScanner.nextLine();

        System.out.println("Please enter your telephone (+44): ");
        long telNumber = myScanner.nextLong();


               Personal User = new Personal(forename,surname,dob ,add1,add2,county,postCode,telNumber);

               System.out.println("The users name is: " + forename + " " + surname);
               System.out.println("The users address is");
               System.out.println (add1);
               System.out.println (add2);
               System.out.println (county);
               System.out.println (postCode);
               System.out.println ("Telephone Number:" + telNumber);
                       Connection conn = null;

        try
        {
            String userName = "uname";
            String password = "password";
            String url = "jdbc:mysql://localhost:3306/test";
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection(url, userName, password);
            System.out.println("connection established");
            Statement statement = conn.createStatement();
 String createTable = "CREATE TABLE user (forename CHAR(10),surname CHAR(10), dob CHAR(50), add1 CHAR(50), add2 CHAR(50), county CHAR(50), postcode CHAR(50), telnumber CHAR(50))";
        String insertRows1 = "INSERT INTO user VALUES (forename, surname, dob, add1, add2, county, postCode, telNumber)";



        String select = "SELECT * FROM user";

		//Execute  SQL
  		statement.executeUpdate(createTable);
		statement.executeUpdate(insertRows1);


		// Create a results set and read through results
		ResultSet rset = statement.executeQuery(select);
		while (rset.next() == true)   // or simpily rset.next()
        {
    		System.out.print(rset.getString(1)+"\t");
    		System.out.println(rset.getString(2));
		}
		rset.close();


        conn.close();
        }
        catch (Exception e)
        {
            System.err.println("cant connect");
        }
        finally
        {
            if (conn != null)
            {
               try
               {


                   conn.close ();
                   System.out.println("Connection terminated");
               }
               catch (Exception e) { }
            }
        }
        }

}

You are executing this statement, exactly as is "INSERT INTO user VALUES (forename, surname, dob, add1, add2, county, postCode, telNumber)" That does not contain any of the information that you collected above it. It's just that string as written.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.