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;

            String userName = "uname";
            String password = "password";
            String url = "jdbc:mysql://localhost:3306/test";
            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

		// Create a results set and read through results
		ResultSet rset = statement.executeQuery(select);
		while (rset.next() == true)   // or simpily rset.next()

        catch (Exception e)
            System.err.println("cant connect");
            if (conn != null)

                   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.

This article has been dead for over six months. Start a new discussion instead.