Login in console using jdbc

In this blog we will know to validate user name and password by using a table named as login having columns as uname and pass using jdbc. If valid credentials are provided then it will show the welcome: username otherwise Invalid user name and password.


Here we use Type-1 driver (JDBC-ODBC bridge)


Creation of dsn(database source name) for Oracle


Start-Control panel- Administrative Tools- Data Sources (ODBC)-go to system dsn tab-click add button-select a driver for which you want to set up data source (for Oracle- Oracle in XE)-select it and click finish-give any name in data source name textbox-then click ok button.


Note: - Here Username=system, Password=pintu and Dsn name= dsnlogin


Table Creation with values

create table login(uname varchar(50),pass varchar(50))


insert into login values('raj','raj123')

insert into login values('ravi','ravi123')

insert into login values('rahul','rahul123')


import java.sql.*;

import java.util.*;

public class login{

public static void main(String args[]) throws Exception



Connection con=DriverManager.getConnection("jdbc:odbc:dsnlogin","system","pintu");

Statement stmt=con.createStatement();

Scanner sc=new Scanner(System.in);

System.out.print("Enter the user id : ");

String str1=sc.next();

System.out.print("Enter the password : ");

String str2=sc.next();

ResultSet rs=stmt.executeQuery("select * from login where uname='"+str1+"' and pass='"+str2+"'");


System.out.println("Welcome::: "+str1);


System.out.println("Invalid user name and password");






Javac login.java

Java login