• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jdbc + Variable j  RSS feed

 
Eric Habils
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi the Community,

I have a jframe with 3 textfields>
MatriculeToFind
MatriculeFinded
Name

The target is when I introduce id number in MatriculeTofind the program insert the id and the name into MatriculeFinded and nameFinded.

But in the program the result is null.

where is my error.

Thanks

Habiler

 
Paul Clapham
Sheriff
Posts: 22099
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Habils wrote:But in the program the result is null.


The result? I don't understand what you mean by "the result". It's a void method so it doesn't return any value, so clearly you must have something else in mind.
 
Eric Habils
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The textFields MatriculeFinded and NameFinded are empty<  But when i replace the ? by a valid id number its ok

thanks
 
Paul Clapham
Sheriff
Posts: 22099
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So that ? in the PreparedStatement is supposed to be some kind of number? In that case passing it the string "MatriculeToFind" is naturally going to result in the query returning zero rows, which is what is happening.

In other words, you have (at least) two problems: first, you don't have a way to tell the user that the ID number isn't in the table, which can happen when you pass the query an ID number which isn't there. And second, you aren't even passing an ID number to the query. I imagine that you thought that "MatriculeToFind".toString() would do something with the variable MatriculeToFind, but it doesn't. It is simply the string literal "MatriculeToFind" instead. And anyway using the MatriculeToFind variable would be pointless because it's null.

Perhaps you meant to get an ID number from somewhere and put it into that variable? If so you should really declare it as an int variable. And you do need some code which assigns it a value.

And why is that method given a MouseEvent as a parameter? It isn't used in the method, for one thing.
 
Eric Habils
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ve supressed the toString and replaced the ""String"" by int but no changes
Where do I filling the variable MatriculeToFind ?
Habiler
 
Knute Snortum
Sheriff
Posts: 3436
85
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Habils wrote:I ve supressed the toString and replaced the ""String"" by int but no changes
Where do I filling the variable MatriculeToFind ?
Habiler

I'm assuming that MatriculeToFind is a text field that contains the ID of the row you want to query.  I would need to see the rest of the program to be sure, but if you've declared MatriculeToFind outside of any method, constructor, or initializer block, then should be able to do something like this:

I haven't included the code to validate that MatriculeToFind is truly a positive integer.
 
Eric Habils
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now its give me an error at String idText = MatriculeToFind.getText();String

 
Knute Snortum
Sheriff
Posts: 3436
85
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) What is the error?  Please post the full error text.
2) You're not showing the full program. We need the full program to see where MatriculeToFind is declared.
 
Eric Habils
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My error is on line              rs.getString(1,MatriculeToFind);





Error :
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36164
439
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you have these two commands sequentially:


You need this in between to actually replace the ? with a value:


You had this in all earlier post/iteration. Looks like it got lost in refactoring.
 
Eric Habils
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I have a nullPointerException at line             ps.setString(1,"MatriculeToFind");

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36164
439
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't be getting a null pointer there. You should be getting it on:


I don't see anywhere you create the connection.
 
Eric Habils
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
at line 28 is the DB connected
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36164
439
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Habils wrote:at line 28 is the DB connected


Ah. This is line 28.


But on line 101, you have


These are two different local variables that just happen to have the same name.
 
Knute Snortum
Sheriff
Posts: 3436
85
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure this is what you want?

Don't you want to get the text from the MatriculeToFind textfield, validate it, and convert it to an integer like we talked about?
 
Eric Habils
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello to all,

I va suppressed and replaced by and it seems to run run.

Thanks for all

Habiler
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!