This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC Java Application not working

 
Dene Lamprecht
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi people

I would appreciate some help, I am building a Java Application using Netbeans 5.5 and a Ms SQL Server 2000 database. It is a program for a Video Store.
I am busy with an edit interface where the user can add a genre or movie or delete a movie from the database. But I need to make the user enter a username and password before any editing can be done.

I've created a JtextField for the USERNAME and a JPasswordField for the PASSWORD. I am trying to match the USERNAME and PASSWORD against the database.
The program does not return any errors, but if I press Login nothing happens. This is the part for the Login Screen:


From part:
String data = "jdbcdbc:VideoStore";
is where the action happens for the login.

I know it is not very secure but this is only a project for school, I just need it to be able to login.

Thank you in advance
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dene,
You are "swallowing" any database exceptions that occur:


Can you try adding "d.printStackTrace()" to see what is the actual database error message?
 
Dene Lamprecht
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the reply Jeanne, I have changed that specific piece of code to:


But still when I run the program and click the LOGIN button I get no exception or any printout. If I can at least get an error I can try to fix it.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the jButton1ActionPerformed method being called?
 
Dene Lamprecht
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf I am not sure what you mean, I have added an event ActionPerformed to jButton1 and written the database connection code inside the event.

Is that the correct way?
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it doesn't matter what's inside the action listener if it's not being run for some reason :-) Put a System.out.println statement at the beginning of the jButton1ActionPerformed method to check if it's actually being called.
 
Somnath Mallick
Ranch Hand
Posts: 482
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the variable "data" be static if its in outside any method (...i mean, if its a variable declared at class level)! Although your middle part of the code is a bit complicated to look at.
Few things:


No need to retrieve it in every loop. Putting un, pass and pw outside the loop would be better.

Also modify your SQL query to something like:


If it returns a row in a ResultSet, then the user name, password exists and this would make the redundant looping go away make would optimize the code a little.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic