CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2009
    Posts
    105

    NullPointerException Java MySQL problem

    Hello, i'm working with SQL's and in this bit of code i'm basically trying to fetch the data located in the 'date' column in my table.

    Code:
                    Statement pStmt = null;
    		pStmt.executeUpdate("SELECT date FROM " + ticker);
    		RS = pStmt.getResultSet();
    		ArrayList<Date> dates = new ArrayList<Date>();
    		while(RS.next())
    		{
    			if(RS.wasNull())
    				System.out.println("Null");
    			else
    				System.out.println("Not Null");
    			System.out.println(RS.getDate(1));
    			dates.add(RS.getDate(1));
    		}
    However the error i am getting is this:

    Code:
    Exception in thread "main" java.lang.NullPointerException
    	at Main.Database.getDateData(Database.java:193)
    	at Main.Main.main(Main.java:23)
    The line the nullPointer is coming up at is in red.

    I have tried using both executeQuery and executeUpdate.

    Thanks

    -Alex

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: NullPointerException Java MySQL problem

    Quote Originally Posted by Alexz003 View Post
    Hello, i'm working with SQL's and in this bit of code i'm basically trying to fetch the data located in the 'date' column in my table.
    Code:
                    Statement pStmt = null;
    		pStmt.executeUpdate("SELECT date FROM " + ticker);
    However the error i am getting is this:

    Code:
    Exception in thread "main" java.lang.NullPointerException
    	at Main.Database.getDateData(Database.java:193)
    	at Main.Main.main(Main.java:23)
    The line the nullPointer is coming up at is in red.
    You set the Statement pStmt to null. And after that you are trying to execute
    Code:
    pStmt.executeUpdate(...);
    with the NULL-pointer!
    So why do you wonder getting the error message?
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2009
    Posts
    105

    Re: NullPointerException Java MySQL problem

    I actually figured it out.

    Originally i was using a PreparedStatement and set it = to null. i forgot to prepare the statement and then execute it...

    So the final code was

    Code:
                    PreparedStatement pStmt = conn.prepareStatement("SELECT date FROM " + ticker);
    		pStmt.executeQuery();
    		RS = pStmt.getResultSet();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured