TYPE 4 DRIVER PROGRAM
FOR DEVELOPING LOGIN APP*/
package jdbcProject;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;
public class LoginApp {
public static void main(String[] args) {
Scanner sc=null;
String user=null,pass=null;
Connection con=null;
ResultSet rs=null;
Statement st=null;
String query=null;
int count=0;
try{
sc=new Scanner(System.in);
if(sc!=null){
System.out.println("enter username:");
user=sc.nextLine();
System.out.println("enter passowrd:");
pass=sc.nextLine();
}
user= ""+user+"";
pass= ""+pass+"";
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","mahesh","mahesh");
if(con!=null)
st=con.createStatement();
System.out.println(query);
if(st!=null)
rs=st.executeQuery(query);
if(rs!=null){
if(rs.next())
count=rs.getInt(1);
System.out.println(count);
}
if(count==0)
System.out.println("invalid credentials");
else
System.out.println("valid credentials");
}
catch(SQLException se){
se.printStackTrace();
System.out.println("recoed insertion failed");
}
catch(ClassNotFoundException cnf){
System.out.println("record insertion failed");
}
catch(Exception e){
System.out.println("recoed insertion failed");
e.printStackTrace();
}
finally{
try{
if(rs!=null)
rs.close();
}
catch(SQLException se){
se.printStackTrace();
}
try{
if(st!=null)
st.close();
}
catch(SQLException se){
se.printStackTrace();
}
try{
if(con!=null)
con.close();
}
catch(SQLException se){
se.printStackTrace();
}
try{
if(sc!=null)
sc.close();
}
catch(Exception se){
se.printStackTrace();
}
}
}
}
No comments:
Post a Comment