You are on page 1of 8

Experiment -3.

Student Name: Harjit Singh Dhillon UID: 20BCS6512


Branch: AIML Section/Group: 20AIML 3A
Semester: 4th
Subject Name: Java Lab Subject Code: 20-csp-287

1. Aim of the practical:

Create a console based application using Java as frontend and Oracle as backend for their
Inventory and Sales maintenance.

2. Apparatus Required: VS Code/ Eclipse IDE/ IntelliJ IDEA

3. Code:

import java.sql.*;

import java.util.Scanner;

public class SQL {

public static void main(String[] args) {

try{
String name1=null;

String prod=null;

int qt;

@SuppressWarnings("resource")
Scanner sc=new Scanner(System.in);

System.out.print("Enter the name of customer,product and quantity:");

System.out.println();

name1=sc.next();

prod=sc.next();

qt=sc.nextInt();

Class.forName("com.mysql.cj.jdbc.Driver");

Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/aryangupta","root","ag1234");

Statement stmt=con.createStatement();

PreparedStatement ps=con.prepareStatement("insert into inventory values(?,?,?)");


ps.setString(1,name1);

ps.setString(2,prod);

ps.setInt(3,qt);

ps.executeUpdate();

System.out.println("Successfully Inserted!");

ResultSet rs=stmt.executeQuery("select * from inventory");

System.out.println("Contents of the Table Inventory are:");

while(rs.next())

System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getInt(3));

System.out.println("Successfully Inserted!");

con.close();

}catch(Exception e){ System.out.println(e);}


}

4. Output:
Learning outcomes (What I have learnt):

1. I have learnt about oracle

2. I have learnt about JDBC

3. I have learnt how to connect frontend and backend

4. I have learnt about different drivers.

Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.
2.
3.

You might also like