Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Update Database

 
Sander Silva
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I'm working with Java, MS Access project. I'm trying to prepare a
Gui for updating.
I need to update the species column of Main tale when it is equal to
the primary key of that table (SVID)
below query and java code gave lot of errors.

here's what i need to do
ex: I need to change the one species of the Main table when SVID
equal to some value.





Please help
 
Paul Clapham
Sheriff
Posts: 21149
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Errors? Those error messages are there to explain to you what went wrong. You should read them.

And if you're going to ask somebody else about the error messages, you should show them the error messages.

As for my guess about the problem you're having, I would recommend you use a PreparedStatement in that code. I know you already know about PreparedStatement because you used one in the last piece of code you posted.
 
Mike Zal
Ranch Hand
Posts: 144
Fedora Java Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like the reason you are getting errors is because you have an unnecessary ') after the integer value SVID and do not have single quotes around the String species value.

With that aside, you should not using executeUpdate to see if your query even affected the database. You should be using a PreparedStatement instead of a regular Statement. What happens if someone enters "1); delete from Main;//" into the SVID value?
 
Sander Silva
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for reply, Really appreciate your kind help.

I used PreparedStatement



Im getting this error when I add 140 add SVID in my Gui,

Error: java.lang.NullPointerException

Please help
 
Paul Clapham
Sheriff
Posts: 21149
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, no, no.


As for the error message, it may or may not have anything to do with your bad try at PreparedStatement. Look at the stack trace; it tells you exactly what line of code threw the exception.
 
Sander Silva
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you again and again for kind help, Really appreciate your
kind help.

Can't tell exactly what is the line.

it shows

Error: java.lang.NullPointerException

Here's how my current code looks like

UpdateGui.java


UpdateCode.java


I'm new 2 Java. Please help me.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In which line are you getting the exception? Put e.printStackTrace() in all catch blocks and post the full stack trace. Just seeing the textual error message doesn't really help us help you.
 
srinivas srinivasmeenavalli
Ranch Hand
Posts: 65
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Add System.out.printls to your code . Track SVID, Species,DBConn,S variable values by adding System.out.printl's.
Do you know how to debug a Java application ?Which Java editor you are using for right now ? Java IDE provides Debug facilities by default .
check this
 
Sander Silva
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for kind help.

I'm using NetBeans 7.0
 
Sander Silva
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:In which line are you getting the exception? Put e.printStackTrace() in all catch blocks and post the full stack trace. Just seeing the textual error message doesn't really help us help you.


I add e.printStackTrace() to all catch blocks, Even it is difficult for me. Please tell me
is this the correct way of adding e.printStackTrace() to catch blocks.



I also add import java.lang.reflect.*; to the top.
Both newly added parts are highlighted in yellow.

Please help.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell me is this the correct way of adding e.printStackTrace() to catch blocks.

Does it work?

I also add import java.lang.reflect.*; to the top.

Why did you do that? Are you planning on using reflection? Anyway, the coloring is probably just the IDE's way of telling you that those imports are not used.
 
Sander Silva
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again for help,

I remove import java.lang.reflect.*;, It's not valuable.

I'm still getting the error.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't post the stack trace, then there's really no way for us to help you.
 
Fatih Keles
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same issue as it is in your older thread Delete-Records-form-Database
 
Sander Silva
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for kind help,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic