SlideShare une entreprise Scribd logo
1  sur  3
Assignment-1
package R100212049.AbhinavKhurana.ques1;
import java.io.*;
import java.sql.*;
import java.util.*;
public class q1 {
public static void main(String[] args) throws Exception {
String h = null;
StringBuffer sb;
Class.forName("com.mysql.jdbc.Driver");
Properties prop=new Properties();
String url="jdbc:mysql://localhost:3306/db1";
prop.setProperty("user", "root");
prop.setProperty("password", "admin");
Connection conn= DriverManager.getConnection(url, prop);
Statement stmt=conn.createStatement();
// stmt.executeUpdate("create table INFO(name varchar(30),pass varchar(30))");
do{
System.out.println("LOGIN SYSTEM");
System.out.println("Enter your choice");
System.out.println("1.Register");
System.out.println("2.Login");
System.out.println("3.View Users");
System.out.println("4.Show Database State");
Scanner sc= new Scanner(System.in);
int i=sc.nextInt();
switch (i) {
case 1:
sb=new StringBuffer();
System.out.println("Enter username");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String fname=br.readLine();
for(int l=0;l<fname.length();l++)
{
char ch=fname.charAt(l);
ch=(char) (ch+1);
sb.append(ch);
}
fname=new String(sb);
System.out.println("Enter the password");
String pwd=br.readLine();
System.out.println("ReEnter your password ");
String rpwd=br.readLine();
sb=new StringBuffer();
if(pwd.equals(rpwd))
{
for(int l=0;l<pwd.length();l++)
{
char r=pwd.charAt(l);
r=(char)(r+1);
sb.append(r);
}
pwd=new String(sb);
System.out.println("Account Sucessfully created");
PreparedStatement pst= conn.prepareStatement("insert into INFO
values(?,?)");
pst.setString(1,fname);
pst.setString(2,pwd);
pst.executeUpdate();
}
else
{
System.out.println("Password doesn't match");
}
break;
case 2:
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Username");
String lname=b.readLine();
System.out.println("Enter Password");
String lpwd=b.readLine();
sb=new StringBuffer();
for(int l=0;l<lname.length();l++)
{
char ch1=lname.charAt(l);
ch1=(char) (ch1+1);
sb.append(ch1);
}
lname=new String(sb);
PreparedStatement st=conn.prepareStatement("select pass from INFO where
name=?");
st.setString(1,lname);
ResultSet rs=st.executeQuery();
sb=new StringBuffer();
while(rs.next())
{
h=rs.getString(1);
for(int l=0;l<h.length();l++)
{
char r=h.charAt(l);
r=(char)(r-1);
sb.append(r);
}
h=new String(sb);
if(h.equals(lpwd))
{
System.out.println("Login successfully");
}
else
{
System.out.println("Wrong Password");
}
}
break;
case 3:
ResultSet ro=stmt.executeQuery("select name from INFO");
while(ro.next())
{
sb=new StringBuffer();
h=ro.getString(1);
for(int m=0;m<h.length();m++)
{
char r=h.charAt(m);
r=(char)(r-1);
sb.append(r);
}
h=new String(sb);
System.out.println(h);
}
break;
case 4:
ResultSet r=stmt.executeQuery("select * from INFO");
while(r.next())
{
System.out.println(r.getString(1)+" "+r.getString(2));
}
break;
default:
System.out.println("Wrong choice");
break;
}
}while (true);
}
}

Contenu connexe

Tendances

Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Arian Gutierrez
 

Tendances (18)

Micro(Lightweight) Django
Micro(Lightweight) DjangoMicro(Lightweight) Django
Micro(Lightweight) Django
 
Custom faultpolicies
Custom faultpoliciesCustom faultpolicies
Custom faultpolicies
 
Entity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net CoreEntity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net Core
 
C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter
C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter
C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter
 
Storing 16 Bytes at Scale
Storing 16 Bytes at ScaleStoring 16 Bytes at Scale
Storing 16 Bytes at Scale
 
Serial Killers - or Deserialization for fun and profit
Serial Killers - or Deserialization for fun and profitSerial Killers - or Deserialization for fun and profit
Serial Killers - or Deserialization for fun and profit
 
Hadoop
HadoopHadoop
Hadoop
 
Google App Engine Developer - Day3
Google App Engine Developer - Day3Google App Engine Developer - Day3
Google App Engine Developer - Day3
 
Html web sql database
Html web sql databaseHtml web sql database
Html web sql database
 
TDD in the wild
TDD in the wildTDD in the wild
TDD in the wild
 
Java设置环境变量
Java设置环境变量Java设置环境变量
Java设置环境变量
 
Zabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet MensZabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet Mens
 
MongoDB-SESSION03
MongoDB-SESSION03MongoDB-SESSION03
MongoDB-SESSION03
 
Nantes Jug - Java 7
Nantes Jug - Java 7Nantes Jug - Java 7
Nantes Jug - Java 7
 
groovy databases
groovy databasesgroovy databases
groovy databases
 
Testing with Node.js
Testing with Node.jsTesting with Node.js
Testing with Node.js
 
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
Tipo virus espia con esto aprenderan a espiar a personas etc jeropas de mrd :v
 
Cassandra 2.2 & 3.0
Cassandra 2.2 & 3.0Cassandra 2.2 & 3.0
Cassandra 2.2 & 3.0
 

En vedette (17)

REMS in the Community Pharmacy - lesson to Post
REMS in the Community Pharmacy - lesson to PostREMS in the Community Pharmacy - lesson to Post
REMS in the Community Pharmacy - lesson to Post
 
1. Title pages
1. Title pages1. Title pages
1. Title pages
 
Birkbeck Babylab Newsletter 2011
Birkbeck Babylab Newsletter 2011Birkbeck Babylab Newsletter 2011
Birkbeck Babylab Newsletter 2011
 
Lect14
Lect14Lect14
Lect14
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
 
Lecture03 p1
Lecture03 p1Lecture03 p1
Lecture03 p1
 
lesson - Patient Safety and Spanish in the Pharmacy - to post
lesson - Patient Safety and Spanish in the Pharmacy - to postlesson - Patient Safety and Spanish in the Pharmacy - to post
lesson - Patient Safety and Spanish in the Pharmacy - to post
 
Opioids to Minors and Drug Donation Programs - lesson
Opioids to Minors and Drug Donation Programs - lessonOpioids to Minors and Drug Donation Programs - lesson
Opioids to Minors and Drug Donation Programs - lesson
 
Code
CodeCode
Code
 
Aplikom
AplikomAplikom
Aplikom
 
Course plan computer graphics
Course plan computer graphicsCourse plan computer graphics
Course plan computer graphics
 
Course plan computer graphics lab
Course plan computer graphics labCourse plan computer graphics lab
Course plan computer graphics lab
 
Graphics devices
Graphics devicesGraphics devices
Graphics devices
 
The stuarts
The stuartsThe stuarts
The stuarts
 
Mathematical elements-for-computer-graphics-1
Mathematical elements-for-computer-graphics-1Mathematical elements-for-computer-graphics-1
Mathematical elements-for-computer-graphics-1
 
Graphics pdf
Graphics pdfGraphics pdf
Graphics pdf
 
B spline
B splineB spline
B spline
 

Similaire à Java assgn

Photo Insert and Retrieve App
Photo Insert and Retrieve AppPhoto Insert and Retrieve App
Photo Insert and Retrieve App
Peeyush Ranjan
 
Transaction Management Tool
Transaction Management ToolTransaction Management Tool
Transaction Management Tool
Peeyush Ranjan
 
This is a basic JAVA pgm that contains all of the major compoents of DB2
This is a basic JAVA pgm that contains all of the major compoents of DB2This is a basic JAVA pgm that contains all of the major compoents of DB2
This is a basic JAVA pgm that contains all of the major compoents of DB2
Sheila A. Bell, MS, PMP
 
Hibernate Import.Sql I18n
Hibernate Import.Sql I18nHibernate Import.Sql I18n
Hibernate Import.Sql I18n
yifi2009
 

Similaire à Java assgn (20)

Import java
Import javaImport java
Import java
 
Scrollable Test App
Scrollable Test AppScrollable Test App
Scrollable Test App
 
Batch processing Demo
Batch processing DemoBatch processing Demo
Batch processing Demo
 
Teste de Integração com DbUnit e jIntegrity
Teste de Integração com DbUnit e jIntegrityTeste de Integração com DbUnit e jIntegrity
Teste de Integração com DbUnit e jIntegrity
 
Cursor Demo App
Cursor Demo AppCursor Demo App
Cursor Demo App
 
Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1Tomcat连接池配置方法V2.1
Tomcat连接池配置方法V2.1
 
Photo Insert and Retrieve App
Photo Insert and Retrieve AppPhoto Insert and Retrieve App
Photo Insert and Retrieve App
 
Transaction Management Tool
Transaction Management ToolTransaction Management Tool
Transaction Management Tool
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
 
Wwe Management System
Wwe Management SystemWwe Management System
Wwe Management System
 
This is a basic JAVA pgm that contains all of the major compoents of DB2
This is a basic JAVA pgm that contains all of the major compoents of DB2This is a basic JAVA pgm that contains all of the major compoents of DB2
This is a basic JAVA pgm that contains all of the major compoents of DB2
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql
 
Library system project file
Library system project fileLibrary system project file
Library system project file
 
JDBC (JAVA Database Connectivity)
JDBC (JAVA Database Connectivity)JDBC (JAVA Database Connectivity)
JDBC (JAVA Database Connectivity)
 
JDBC Tutorial
JDBC TutorialJDBC Tutorial
JDBC Tutorial
 
Fahad project java connectivity
Fahad project java connectivityFahad project java connectivity
Fahad project java connectivity
 
Hibernate Import.Sql I18n
Hibernate Import.Sql I18nHibernate Import.Sql I18n
Hibernate Import.Sql I18n
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring Data
 
Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 

Java assgn

  • 1. Assignment-1 package R100212049.AbhinavKhurana.ques1; import java.io.*; import java.sql.*; import java.util.*; public class q1 { public static void main(String[] args) throws Exception { String h = null; StringBuffer sb; Class.forName("com.mysql.jdbc.Driver"); Properties prop=new Properties(); String url="jdbc:mysql://localhost:3306/db1"; prop.setProperty("user", "root"); prop.setProperty("password", "admin"); Connection conn= DriverManager.getConnection(url, prop); Statement stmt=conn.createStatement(); // stmt.executeUpdate("create table INFO(name varchar(30),pass varchar(30))"); do{ System.out.println("LOGIN SYSTEM"); System.out.println("Enter your choice"); System.out.println("1.Register"); System.out.println("2.Login"); System.out.println("3.View Users"); System.out.println("4.Show Database State"); Scanner sc= new Scanner(System.in); int i=sc.nextInt(); switch (i) { case 1: sb=new StringBuffer(); System.out.println("Enter username"); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String fname=br.readLine(); for(int l=0;l<fname.length();l++) { char ch=fname.charAt(l); ch=(char) (ch+1); sb.append(ch); } fname=new String(sb);
  • 2. System.out.println("Enter the password"); String pwd=br.readLine(); System.out.println("ReEnter your password "); String rpwd=br.readLine(); sb=new StringBuffer(); if(pwd.equals(rpwd)) { for(int l=0;l<pwd.length();l++) { char r=pwd.charAt(l); r=(char)(r+1); sb.append(r); } pwd=new String(sb); System.out.println("Account Sucessfully created"); PreparedStatement pst= conn.prepareStatement("insert into INFO values(?,?)"); pst.setString(1,fname); pst.setString(2,pwd); pst.executeUpdate(); } else { System.out.println("Password doesn't match"); } break; case 2: BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter Username"); String lname=b.readLine(); System.out.println("Enter Password"); String lpwd=b.readLine(); sb=new StringBuffer(); for(int l=0;l<lname.length();l++) { char ch1=lname.charAt(l); ch1=(char) (ch1+1); sb.append(ch1); } lname=new String(sb); PreparedStatement st=conn.prepareStatement("select pass from INFO where name=?"); st.setString(1,lname); ResultSet rs=st.executeQuery(); sb=new StringBuffer(); while(rs.next()) { h=rs.getString(1); for(int l=0;l<h.length();l++) {
  • 3. char r=h.charAt(l); r=(char)(r-1); sb.append(r); } h=new String(sb); if(h.equals(lpwd)) { System.out.println("Login successfully"); } else { System.out.println("Wrong Password"); } } break; case 3: ResultSet ro=stmt.executeQuery("select name from INFO"); while(ro.next()) { sb=new StringBuffer(); h=ro.getString(1); for(int m=0;m<h.length();m++) { char r=h.charAt(m); r=(char)(r-1); sb.append(r); } h=new String(sb); System.out.println(h); } break; case 4: ResultSet r=stmt.executeQuery("select * from INFO"); while(r.next()) { System.out.println(r.getString(1)+" "+r.getString(2)); } break; default: System.out.println("Wrong choice"); break; } }while (true); } }