File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes JDBC Java Application not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Java Application not working" Watch "JDBC Java Application not working" New topic
Author

JDBC Java Application not working

Dene Lamprecht
Greenhorn

Joined: Jun 23, 2009
Posts: 14
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

Joined: May 26, 2003
Posts: 31062
    
232

Dene,
You are "swallowing" any database exceptions that occur:


Can you try adding "d.printStackTrace()" to see what is the actual database error message?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Dene Lamprecht
Greenhorn

Joined: Jun 23, 2009
Posts: 14
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
Marshal

Joined: Mar 22, 2005
Posts: 42923
    
  68
Is the jButton1ActionPerformed method being called?
Dene Lamprecht
Greenhorn

Joined: Jun 23, 2009
Posts: 14
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
Marshal

Joined: Mar 22, 2005
Posts: 42923
    
  68
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

Joined: Mar 04, 2009
Posts: 477
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC Java Application not working