Small Student Project







 Core Java Project :


 Stand alone Application by using core java :


package MyJavaPackage;


import java.sql.*;
import java.util.Scanner;

public class StudentInfo {
public static void insertInfo(Connection con) throws SQLException {
Scanner sc = new Scanner(System.in);
PreparedStatement pst = con.prepareStatement("insert into student values(?,?,?,?,?)");
System.out.println("Enter the Roll Number of the Student :");
int rollno = sc.nextInt();
System.out.println("Enter the First Name of the Student :");
String fname = sc.next();
System.out.println("Enter the Last Name of the Student :");
String lname = sc.next();
System.out.println("Enter the Contact Number of the Student :");
long contact = sc.nextInt();
System.out.println("Enter the City of the Student :");
String city = sc.next();

pst.setInt(1, rollno);
pst.setString(2, fname);
pst.setString(3, lname);
pst.setLong(4, contact);
pst.setString(5, city);
int status = pst.executeUpdate();

if(status==1)
System.out.println("Student Information Successfully Inserted...");
else
System.out.println("Failed to Inserted Information");
}

public static void deleteInfo(Connection con) throws SQLException {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Student Roll No which you want to delete: ");
int rollno = sc.nextInt();
PreparedStatement pst = con.prepareStatement("delete from student where rollno=?");
pst.setInt(1,rollno);
int status = pst.executeUpdate();

if(status==1)
System.out.println("Student Information Deleted Successfully...");
else
System.out.println("Failed to Delete Information");
}
public static void updateInfo(Connection con) throws SQLException {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Student Roll No which you want to updated: ");
int rollno = sc.nextInt();
System.out.println("Which Information you want to update :");
System.out.println("1.Student Contact \n2.Student City");
System.out.println("Enter your choice:");
int ch = sc.nextInt();

switch(ch)
{
case 1: {
PreparedStatement pst = con.prepareStatement("update student set contact=? where rollno=?");
System.out.println("Enter the Student Contact you want to Update :");
long contact = sc.nextLong();

pst.setLong(1, contact);
pst.setInt(2,rollno);
int status = pst.executeUpdate();
if (status == 1)
System.out.println("Student Contact Number Updated Successfully...");
else
System.out.println("Failed to Update Information");
}
break;
case 2: {
PreparedStatement pst = con.prepareStatement("update student set city=? where rollno=?");
System.out.println("Enter the Student City you want to Update :");
String city = sc.next();

pst.setString(1, city);
pst.setInt(2,rollno);
int status = pst.executeUpdate();
if (status == 1)
System.out.println("Student City Updated Successfully...");
else
System.out.println("Failed to Update Information");
}
break;

}

}

public static void display(Connection con)throws SQLException {

Scanner sc = new Scanner(System.in);

Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from student");
System.out.println("\n Student Detail: \n");
while(rs.next())
{
System.out.println(" Roll NO :"+rs.getInt(1)+" First Name :"+
rs.getString(2)+" Last Name :"+rs.getString(3)+
" Contact Detail :"+rs.getLong(4)+" City :"+rs.getString(5) );
}

}
public static void main(String[] args) throws ClassNotFoundException, SQLException {

Scanner sc = new Scanner(System.in);
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/myjava_db","root","swapnil");

boolean b = true;
while(b)
{
System.out.println("\nEnter your choice:");
System.out.println("1.Insert Student Info \n2.Delete Student Info \n3.Update Student Info \n4.Display Detail");
System.out.println("5.Exit");
int ch = sc.nextInt();

switch(ch)
{
case 1 : insertInfo(con);
break;
case 2 : deleteInfo(con);
break;
case 3 : updateInfo(con);
break;
case 4 : display(con);
break;
case 5 : b = false;
break;
default:
System.out.println("Invlid Input");
}
}



}

}

/*
Student Table :

mysql> select * from student;
+--------+---------+--------+---------+----------+
| rollno | fname | lname | contact | city |
+--------+---------+--------+---------+----------+
| 1 | swapnil | jamble | 1111 | pune |
| 2 | om | mane | 54321 | mumbai |
| 3 | rahul | reddy | 1111 | banglore |
| 4 | ganesh | patil | 949449 | karad |
+--------+---------+--------+---------+----------+
4 rows in set (0.00 sec)


Enter your choice:
1.Insert Student Info
2.Delete Student Info
3.Update Student Info
4.Display Detail
5.Exit
1
Enter the Roll Number of the Student :
5
Enter the First Name of the Student :
anvesh
Enter the Last Name of the Student :
reddy
Enter the Contact Number of the Student :
83747
Enter the City of the Student :
Chennai
Student Information Successfully Inserted...

Enter your choice:
1.Insert Student Info
2.Delete Student Info
3.Update Student Info
4.Display Detail
5.Exit
4

Student Detail:

Roll NO :1 First Name :swapnil Last Name :jamble Contact Detail :1111 City :pune
Roll NO :2 First Name :om Last Name :mane Contact Detail :54321 City :mumbai
Roll NO :3 First Name :rahul Last Name :reddy Contact Detail :1111 City :banglore
Roll NO :4 First Name :ganesh Last Name :patil Contact Detail :949449 City :karad
Roll NO :5 First Name :anvesh Last Name :reddy Contact Detail :83747 City :Chennai

Enter your choice:
1.Insert Student Info
2.Delete Student Info
3.Update Student Info
4.Display Detail
5.Exit
3
Enter the Student Roll No which you want to updated:
4
Which Information you want to update :
1.Student Contact
2.Student City
Enter your choice:
2
Enter the Student City you want to Update :
Delhi
Student City Updated Successfully...

Enter your choice:
1.Insert Student Info
2.Delete Student Info
3.Update Student Info
4.Display Detail
5.Exit
4

Student Detail:

Roll NO :1 First Name :swapnil Last Name :jamble Contact Detail :1111 City :pune
Roll NO :2 First Name :om Last Name :mane Contact Detail :54321 City :mumbai
Roll NO :3 First Name :rahul Last Name :reddy Contact Detail :1111 City :banglore
Roll NO :4 First Name :ganesh Last Name :patil Contact Detail :949449 City :Delhi
Roll NO :5 First Name :anvesh Last Name :reddy Contact Detail :83747 City :Chennai

Enter your choice:
1.Insert Student Info
2.Delete Student Info
3.Update Student Info
4.Display Detail
5.Exit
2
Enter the Student Roll No which you want to delete:
4
Student Information Deleted Successfully...

Enter your choice:
1.Insert Student Info
2.Delete Student Info
3.Update Student Info
4.Display Detail
5.Exit
4

Student Detail:

Roll NO :1 First Name :swapnil Last Name :jamble Contact Detail :1111 City :pune
Roll NO :2 First Name :om Last Name :mane Contact Detail :54321 City :mumbai
Roll NO :3 First Name :rahul Last Name :reddy Contact Detail :1111 City :banglore
Roll NO :5 First Name :anvesh Last Name :reddy Contact Detail :83747 City :Chennai

Enter your choice:
1.Insert Student Info
2.Delete Student Info
3.Update Student Info
4.Display Detail
5.Exit


*/

Comments

Popular posts from this blog

Practical slips programs : Machine Learning

Full Stack Developement Practical Slips Programs

MCS Advanced Database & Web Technology