• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java-Mysql How to check username already exist in database?  RSS feed

 
yunus emre güney
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi im trying to create simple mysql java register login system.Actually i did it by watching youtube videos and its working but i couldnt implement username exist in db or not feature.I am posting full code here.

Main class here: not much here


ICrud Interface:



Actually the problem must be here in isUserNameRegistered method i added.



Controller Class: not much here to look i guess


Logic Class with gui.methods are at the end.


SignUpForm Class.Complier shows that error is here.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javamysql.ui.SignupForm.signupActionPerformed(SignupForm.java:136)
at javamysql.ui.SignupForm.access$0(SignupForm.java:133)
at javamysql.ui.SignupForm$1.actionPerformed(SignupForm.java:55)
There are gui stuff first lines.I added extra if statement to signupActionPerformed method  if(!icrudimpl.isUsernameRegistered(this.username.getText()))     but looks like its not working.

 
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
This code never returns false:


A result set is not null. Instead rs.next() returns false if there are no matches.

Also, you should use a PreparedStatement and call code like this


It's easier to read and more secure than concatenating values.
 
Dave Tolls
Ranch Hand
Posts: 2410
25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a lot of PreparedStatements which are not being used correctly.
For example this:


Should look like this:


In addition, there are places where you aren't using PreparedStatements at all, and you should be.
 
yunus emre güney
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi thanks for answering i tried to edit my code as you guys said but still same

 
Dave Tolls
Ranch Hand
Posts: 2410
25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That query is incorrect.
Compare it to the one I posted and you'll see that you are missing the '?' placeholder for the parameter.
That should have resulted in an exception.
 
yunus emre güney
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for everythng guys now its workin
 
Ron McLeod
Saloon Keeper
Posts: 1334
186
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yunus emre güney wrote:


You could reduceto just
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!