• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDBC Java Application not working

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 = "jdbc:odbc: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
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the jButton1ActionPerformed method being called?
 
Dene Lamprecht
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 483
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic