• Post Reply Bookmark Topic Watch Topic
  • New Topic

Prepared Statement  RSS feed

 
Anita Lahav
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


output:


What am I doing wrong with the preparedStatement. It looks right have gone through my book and all the examples and discussions on the net show this. I do not understand what I am doing wrong in Line 40 - 55.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anita Lahav wrote:What am I doing wrong with the preparedStatement...

Anita,

Please DontWriteLongLines. It makes your thread very hard to read, and it's actually bad coding practice.
I've broken yours up this time, but for future reference, please remember:
80 characters max.
(the SSCCE page actually recommends 62)
And that includes string literals AND comments AND large method calls.

Oh, and you're usually better off using spaces for indentation, rather than TABs.

Thanks.

Winston
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

It looks like for some reason the SQL statement doesn't return any results. Do you have another tool which you can use to check what's in the database? Try running your SQL statement with that:

SELECT firstName, lastName FROM Users WHERE userID='000010'

Does it return any rows?
 
Anita Lahav
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
returns Exception in thread "main" java.lang.NullPointerException
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the stack trace of the exception look like? It tells you in exactly what line the exception happens. Something in that line is null that should not be null.

You get a NullPointerException if you try to call a method on a variable that is null.
 
Anita Lahav
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
StockDatabaseQuery.main<StockDatabaseQuery.java:43>

Just started with Java (no tutor to assist) and

(Winston) : I also just started asking on forums. Bit scared of now.

Other question : Using Abstract Classes and Methods the advice put me back to where I was a week ago and still super stuck.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anita Lahav wrote:(Winston) : I also just started asking on forums. Bit scared of now.

No probs. Just remember the business about long lines. You want people to be able to read your posts easily, don't you?

Just started with Java (no tutor to assist) and...

And you're already diving into JDBC? Phew.

I wonder if you may be taking on a bit too much too soon. Programming is not simple.

Other question : Using Abstract Classes and Methods the advice put me back to where I was a week ago and still super stuck.

Then I suggest you post your problems in that thread. And be specfic. "I don't understand" and "it doesn't work" aren't very helpful. You need to tell us what you're stuck on; otherwise it's very difficult to help.

Winston
 
Anita Lahav
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Winston,

Thanks for the advise. Sorted both my queries that I posted. Just took a break and it all worked lol.

Been stuck to the PC from 04:00 am to 08:00pm solid everyday, kids and hubby so brain got jammed.

You guys are very helpful.

Thanks again.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!