Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-25-2008, 11:24 PM
Member
 
Join Date: Jul 2008
Posts: 27
int80 is on a distinguished road
java.lang.NullPointerException in MySQL INSERT
I'm trying to input data into my MySQL database, but keep getting a NullPointerException. It doesn't even say what's causing it.
Code:
public int GroupInsertSQL(int totalPrice){ try{ Statement statement = connection.createStatement(); i = statement.executeUpdate("INSERT INTO group_order VALUES( '" + OrderClass.bookingDate + "', " + "NOW()" + ", " + "'" + totalPrice + "', " + "'" + OrderClass.hireLength +"', " + "'" + OrderClass.numberPeople + "', " + "'" + OrderClass.secondName + ")"); //resultS = statement.executeQuery("SELECT LAST_INSERT_ID()"); }catch(Exception e){System.out.println(e);} return i; }
Do you think it could be caused by dodgy SQL syntax? Or just my Java skills?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-26-2008, 12:19 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Gone to Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
getting a NullPointerException
The source code line number of where the error occurs is in the text of the message. If you want help, you'll have to post the full text of the error message.

Is the value of statement null after the call to connect?
Or is OrderClass null?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-26-2008, 12:38 AM
Member
 
Join Date: Jul 2008
Posts: 27
int80 is on a distinguished road
Quote:
Originally Posted by Norm View Post
The source code line number of where the error occurs is in the text of the message. If you want help, you'll have to post the full text of the error message.

Is the value of statement null after the call to connect?
Or is OrderClass null?
Thanks norm, I worked it out - it was "connection", it was null. I need to open another connection for some reason.

There's another issues now, but I think I know what it is.

Code:
+-------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+----------------+ | groupID | int(11) | NO | PRI | NULL | auto_increment | | bookingDate | varchar(10) | NO | | NULL | | | actualDate | datetime | YES | | NULL | | | totalCost | int(11) | NO | | NULL | | | hireLength | int(11) | NO | | NULL | | | noPeople | int(11) | NO | | NULL | | | sName | varchar(25) | YES | | NULL | | +-------------+-------------+------+-----+---------+----------------+
I'm getting this "Invalid Query: Column Count Doesn't Match Value Count At Row 1" when I try and insert this:

Code:
"INSERT INTO group_order VALUES( '" + OrderClass.bookingDate + "', " + "NOW()" + ", " + "'" + totalPrice + "', " + "'" + OrderClass.hireLength +"', " + "'" + OrderClass.numberPeople + "', " + "'" + OrderClass.secondName + "')"
I haven't accounted for the auto_incrementing groupID. I was under the impression MySQL created it for you? As it obviously doesn't, how do you account for that in the INSERT command?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-26-2008, 12:46 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Gone to Costa Rica
Posts: 2,223
Norm is on a distinguished road
Now your talking SQL and not java.
You'll have to wait for someone that knows SQL.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-28-2008, 08:05 PM
ProjectKaiser's Avatar
Member
 
Join Date: Aug 2008
Location: Saint-Petersburg, Russia
Posts: 47
ProjectKaiser is on a distinguished road
Rewrite the beginning of your query as

"INSERT INTO group_order(bookingDate, actualDate, totalCost, hireLength, noPeople, sName) VALUES( ' " + the rest of your code.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 10-20-2008, 08:31 AM
Member
 
Join Date: Jun 2008
Posts: 15
kicksfanscom is on a distinguished road
Very interesting site, thank you!.txt
Very interesting site, thank you!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
java.lang.NullPointerException stevemcc AWT / Swing 2 02-08-2008 11:01 AM
java.lang.NullPointerException ravian New To Java 1 01-13-2008 09:39 PM
AWT-EventQueue-0 java.lang.NullPointerException susan NetBeans 2 07-16-2007 08:21 AM
java.lang.NullPointerException Felissa Advanced Java 1 07-05-2007 08:02 AM
Error Java.lang.NullPointerException in JBuilder2006 Jack Other IDEs 2 07-02-2007 04:29 AM


All times are GMT +3. The time now is 02:15 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org