Hello youtube this is me indra and today i am going to show you how to create login form
in java using netbeans and linking it with sql server in the previous video also i have
done the same but it works for netbeans with a version less than 8 so in this video i will
be creating the tutorial or the project that works in every versions of netbeans so to
start our project let us start the let us create a database at first so provide the
username and password and click on connect then after right click on the database and
click on new database and provide the name of database testdb then click on ok let me
expand this and this one also testdb which is our database and then after right click
on table to create a new table which will store our username and password first of all
symbol number this will be integer without null then username this will be varchar password
this also will be varchar and let the symbol number be our primary key and also auto increment
it make it yes now this will be auto incremented and ctr + s to save name of our table let
it be test click on ok we can view over here our table test i will insert a row data username
indra password 12345 let me check whether this is save or not select on top 1000 rows
ok it is saved now so our database work is finished let me minimized this and open the
netbeans so we need to create a new project click on new project then after in java categories
choose java project application and click on next then after write the name of the project
testlogin or logintest anything you can write donot create the main class and click on finish
let me expand this right click on the source package and go to new and click on jFrameForm
so write the name of our class name loginCheck then click on finish so this is the area where
we have to design our login page or login window so we need to label one for username
and the other for password then after one text field for username another password field
for password and two buttons one for sign in and the other for reset so let me edit
the name this is username and this one is password stretch this one same for this also
ok i will change the variable name also right click on this click on change variable name
this is username click on ok this is password ok and this is sign in button signin let me
change its variable name also sign in this is reset button rename this also ok now we
have to perform the action when we click on the sign in button so double click on the
sign in button ok now we have to write our code over here what action we have to perform
when we click on sign in button we have to check whether the typed in information is
typed in information matched with the database information that is if username and password
is provided by user it should match with the data that is store in the database so i have
the code here so let me copy and paste this in our project let me show you all the code
so we have to import the connection to import the connection click on this like a bulb symbol
then add import the connection for preparestatement also do the same also for the result set add
import also for joption pane also then after ok its fine now ok driver manager we have
left it ok this is the code what we have to do is we have to include it in the try and
catch block class for name and class for name is the specify what kinds of driver we are
using that is microsoft sql server jdbc driver and this will establish the connection jdbc
sql server and local host with the database name testdb and user is sa and password is
orchid and it will establish the connection by providing the string type url ok this much
here now we have to import a jar file to establish the connection between netbeans and sql server
for that right click on the for that you have to download the jar file from the internet
i will provide the link in the description box so here right click on the library folder
then after click on add jar file folder then i have store it in d drive sql jdbc 6.0 click
on sql jdbc 4.jar and click on open let me expand this it arrives over here now this
is our coding for the sign in button ok let me tell you one thing that you may get error
when you provide this information what error you may get is there may not be the tcp connection
tcp connection may be disabled in the computer for that what you have to do is go to programs
then after sql server configuration manager sql server configuration manager click on
yes then this tcp/ip status is disabled you have to enable this enable this one click
on ok you have to start the sql server management studio restart the sql server management studio
then after again right click on it and go to properties the go to ip address and go
down and in ip all the tcp port is empty you have to write 1433 because we have used 1433
port in the code then click on apply and click on ok and again click on ok let me close this
here we have used port 1433 so i have place the same port number over there then after
let me run this program once let me provide some data value over there it may take some
time for the first time ok it show me the error tcp connection to the local host ok
i haven't restarted the sql server management studio so i shows this error let me restart
this right click on the server then click on restart then click on yes it will restart
the sql server then after click on yes ok let me run the program once let me close this
and run it again now this is correct it says username and password not correct because
i have provided garbage value let me provide correct value indra 12345 then click on sign
in it says username and password match ok now this works for us let me close this and
i will show you i will show you how to code for the reset button also double click on
the reset then after you have to code over here for this what you have to write is username
username.setText this will be empty similarly for password also password .setText ok this
will reset the value let me show you if i type some information and when i press reset
button that will go out then after when user provide information is correct you have to
go to the next window for that what you have to do is create a new jframe form then click
on right click on source package and click on jframe form and type in form me success
if valid username and password is provided it will go to the success class jframe form
then click on finish ok i will take this when the username and password is correct i will
take it to the success.java class for that what i have to do is over here i have to write
the code it will display the message and when i press the ok button it will display the
success window for that success success field = new success then after field . set visible
this will be true then i have to close the original window login window for that setvisible
fale spelling wrong here succes make it the same or you can change over here also that
will not create any problem ok let me run this once indra 12345 ok username and password
match click on ok so thanks for watching please hit like button and subscribe my channel thank
you