0% found this document useful (0 votes)
2 views10 pages

Java JDBC Book and Student Management

The document contains two Java programs for managing data in a MySQL database: one for books and another for students. Each program allows for inserting, updating, deleting, and selecting records, with the student program also including a calculation of total scores and percentages. Both programs utilize JDBC for database connectivity and user input is handled through the console.

Uploaded by

arpitchristian00
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

Java JDBC Book and Student Management

The document contains two Java programs for managing data in a MySQL database: one for books and another for students. Each program allows for inserting, updating, deleting, and selecting records, with the student program also including a calculation of total scores and percentages. Both programs utilize JDBC for database connectivity and user input is handled through the console.

Uploaded by

arpitchristian00
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

program 1: Book

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

class I1

public void insert_data() throws ClassNotFoundException, SQLException

// TODO Auto-generated method stub

[Link]("[Link]");

Connection
con=[Link]("jdbc:mysql://localhost:3306/bhumi","root","");

String sql = "INSERT INTO Book (Book_id, Tittle, Author_name, price )


VALUES(?, ?, ?, ?)";

PreparedStatement stmt = [Link](sql);

[Link](1, "1001");

[Link](2, "mylife");

[Link](3, "bhumi chavda");

[Link](4, "125");

int rowsInserted = [Link]();

if (rowsInserted > 0) {

[Link]("A new user was insered successfully!");


}

public void update_data() throws ClassNotFoundException, SQLException

[Link]("[Link]");

Connection
con=[Link]("jdbc:mysql://localhost:3306/bhumi","root","");

String sql = "UPDATE Book SET Tittle=? where Book_id=?";

PreparedStatement stmt = [Link](sql);

[Link](1, "bhumika");

[Link](2, "1001");

int rowsupdateed = [Link]();

if (rowsupdateed > 0) {

[Link]("A existing was updated successfully!");

public void delete_data() throws ClassNotFoundException, SQLException

[Link]("[Link]");

Connection
con=[Link]("jdbc:mysql://localhost:3306/bhumi","root","");

String sql = "DELETE FROM Book WHERE Book_id=?";

PreparedStatement stmt = [Link](sql);

[Link](1, "2");

int rowsDeleted = [Link]();


if (rowsDeleted > 0) {

[Link]("A new user was deleted successfully!");

public void select_data() throws ClassNotFoundException, SQLException

[Link]("[Link]");

Connection
con=[Link]("jdbc:mysql://localhost:3306/bhumi","root","");

Statement stmt=[Link]();

ResultSet rs=[Link]("SELECT * FROM Book where Book_id");

while([Link]())

[Link]("Book_id= "+[Link](1)+" Tittle = "+[Link](2)+"


Author_name ="+[Link](3)+" Price="+[Link](4));

public class Book {

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

// TODO Auto-generated method stub

Scanner sc=new Scanner([Link]);

I1 i=new I1();

while(true)

[Link]("-Operation-");

[Link](": 1. Insert :");

[Link](": 2. Update :");


[Link](": 3. Delete :");

[Link](": 4. Select :");

[Link](": 5. Exit :");

[Link]("Enter your choice :");

int ch=[Link]();

switch(ch)

case 1:

i.insert_data();

break;

case 2:

i.update_data();

break;

case 3:

i.delete_data();

break;

case 4:

i.select_data();

break;

case 5:

[Link](0);

break;

default:

[Link]("Invalid Choice....");

}
}

program : Student

package DB;

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

class I1

public void insert_data() throws ClassNotFoundException, SQLException

[Link]("[Link]");

Connection
con=[Link]("jdbc:mysql://localhost:3306/bhumi","root","");

String sql = "INSERT INTO student (std_no, std_name,


std_sub1, std_sub2, std_sub3) VALUES(?, ?, ?, ?, ?)";

PreparedStatement stmt = [Link](sql);

[Link](1, "10");

[Link](2, "MR");

[Link](3, "80");
[Link](4, "60");

[Link](5, "80");

int rowsInserted = [Link]();

if (rowsInserted > 0) {

[Link]("A new user was insered successfully!");

public void update_data() throws ClassNotFoundException, SQLException

[Link]("[Link]");

Connection
con=[Link]("jdbc:mysql://localhost:3306/bhumi","root","");

String sql = "UPDATE student SET std_name=?";

PreparedStatement stmt = [Link](sql);

[Link](1, "bbbb");

int rowsupdateed = [Link]();

if (rowsupdateed > 0) {

[Link]("A existing was updated successfully!");

public void delete_data() throws ClassNotFoundException, SQLException

[Link]("[Link]");

Connection
con=[Link]("jdbc:mysql://localhost:3306/bhumi","root","");

String sql = "DELETE FROM student WHERE std_no=?";

PreparedStatement stmt = [Link](sql);


[Link](1, "8");

int rowsDeleted = [Link]();

if (rowsDeleted > 0) {

[Link]("A new user was deleted successfully!");

public void select_data() throws ClassNotFoundException, SQLException

[Link]("[Link]");

Connection
con=[Link]("jdbc:mysql://localhost:3306/bhumi","root","");

Statement stmt=[Link]();

ResultSet rs=[Link]("SELECT * FROM student;");

while([Link]())

[Link]("Roll no = "+[Link](1)+" Name =


"+[Link](2)+" s1 ="+[Link](3)+" s2 ="+[Link](4)+" s3 ="+[Link](5));

public int calculate() throws ClassNotFoundException, SQLException

[Link]("[Link]");

Connection
con=[Link]("jdbc:mysql://localhost:3306/bhumi","root","");

Statement stmt=[Link]();

ResultSet rs=[Link]("SELECT * FROM student;");

while([Link]())

{
int v1 = [Link](3);

int v2 = [Link](4);

int v3 = [Link](5);

int total = v1 + v2 + v3;

float per=total/3;

[Link]("Roll no = "+[Link](1)+" Name =


"+[Link](2)+" s1 ="+[Link](3)+" s2 ="+[Link](4)+" s3 ="+[Link](5)+" Total
= "+total+" per = "+per);

return 0;

public class INSERT {

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


{

// TODO Auto-generated method stub

Scanner sc=new Scanner([Link]);

I1 i=new I1();

while(true)

[Link]("-Operation-");

[Link](": 1. Insert :");

[Link](": 2. Update :");

[Link](": 3. Delete :");

[Link](": 4. DISPLAY :");

[Link](": 5. Exit :");

[Link](": 6. Cale :");

[Link]("Enter your choice :");

int ch=[Link]();
switch(ch)

case 1:

i.insert_data();

break;

case 2:

i.update_data();

break;

case 3:

i.delete_data();

break;

case 4:

i.select_data();

break;

case 5:

[Link](0);

break;

case 6:

[Link]();

break;

default:

[Link]("Invalid Choice....");

You might also like