.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> Javascript >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Login in console using jdbc

Posted By:satyapriyanayak       Posted Date: October 02, 2014    Points: 40    Category: Javascript    URL: http://www.dotnetspark.com  

In this Code Snippets 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


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend