0% found this document useful (0 votes)
10 views7 pages

Java Library Management System Guide

The document outlines a project to develop a Library Management System using Java and JDBC for SQLite database connectivity. It includes code for connecting to the database, performing CRUD operations, and printing a formatted list of books with their ISBNs. The project aims to demonstrate database management and requires the sqlite-jdbc driver for execution.

Uploaded by

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

Java Library Management System Guide

The document outlines a project to develop a Library Management System using Java and JDBC for SQLite database connectivity. It includes code for connecting to the database, performing CRUD operations, and printing a formatted list of books with their ISBNs. The project aims to demonstrate database management and requires the sqlite-jdbc driver for execution.

Uploaded by

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

LIBRARY MANAGEMENT -

DATABASE CONNECTIVITY
BY: DEV SAINI
COURSE: [Link] (AI AND DATA SCIENCE)
AMITY UNIVERSITY
OBJECTIVE

The objective of this project is to develop a simple Library Management System using Java
and JDBC connectivity. The application demonstrates how to connect Java with an SQLite
database, perform CRUD-like operations, and manage library records. This version prints a
formatted list of books including ISBNs, matching the provided output screenshot.
CODE ([Link])

/*
Library Management - Java + JDBC (SQLite)
This program prints user name and course at the top, lists book entries including ISBN,
and prints "library database closed successfully." at the end.

Requires sqlite-jdbc jar on classpath.


Compile:
javac -cp ".:[Link]" [Link]
Run:
java -cp ".:[Link]" LibraryManagementPrint
On Windows use ';' instead of ':' in classpath.
*/

import [Link].*;

public class LibraryManagementPrint {


private static final String DB_URL = "jdbc:sqlite:[Link]";

public static void main(String[] args) {


// Replace these with your actual details
String studentName = "DEV SAINI";
String course = "[Link] (AI AND DATA SCIENCE)";

[Link](studentName);
[Link](course);
[Link]();

Connection conn = null;


try {
conn = [Link](DB_URL);
createTableIfNotExists(conn);
insertSampleDataIfEmpty(conn);
printAllBooksWithISBN(conn);
} catch (SQLException e) {
[Link]("SQL error: " + [Link]());
} finally {
if (conn != null) {
try {
[Link]();
[Link]("library database closed successfully.");
} catch (SQLException e) {
[Link]("Failed to close DB: " + [Link]());
}
}
}
}

private static void createTableIfNotExists(Connection conn) throws SQLException {


String sql = "CREATE TABLE IF NOT EXISTS books (" +
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
"title TEXT NOT NULL," +
"author TEXT," +
"isbn TEXT," +
"total_copies INTEGER DEFAULT 1," +
"available_copies INTEGER DEFAULT 1" +
");";
try (Statement st = [Link]()) {
[Link](sql);
}
}

private static void insertSampleDataIfEmpty(Connection conn) throws SQLException {


String check = "SELECT COUNT(*) FROM books;";
try (Statement st = [Link]();
ResultSet rs = [Link](check)) {
if ([Link]() && [Link](1) == 0) {
String insert = "INSERT INTO books (title, author, isbn, total_copies, available_copies)
VALUES " +
"('Introduction to Java', 'John Doe', '978-3-16-148410-0', 2, 2)," +
"('Data Structures', 'Jane Smith', '978-1-23-456789-0', 2, 2)," +
"('Database Systems', 'Robert Johnson', '978-0-12-345678-9', 1, 1)," +
"('Algorithms Explained', 'Emily Davis', '978-9-87-654321-0', 1, 1);";
[Link](insert);
}
}
}

private static void printAllBooksWithISBN(Connection conn) throws SQLException {


String q = "SELECT id, title, author, isbn FROM books ORDER BY id;";
try (Statement st = [Link]();
ResultSet rs = [Link](q)) {
int idx = 1;
while ([Link]()) {
[Link]("%d. ID: %d, Title: %s, Author: %s,%n ISBN: %s%n",
idx++,
[Link]("id"),
[Link]("title"),
[Link]("author"),
[Link]("isbn"));
}
}
}
}
OUTPUT ( Console Screenshot)
CONCLUSION

This Java console application matches the screenshot-style output by printing the student's
name and course, listing books with ISBNs, and closing the database with a confirmation
message. For submission, include the Java file, the sqlite-jdbc driver, and the generated
[Link] if you want reproducible results.

You might also like