Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
27 views2 pages

JDBC Project Preparation

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

JDBC Project Preparation

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

Project On JDBC : Employee Managementy System

1.create a table employee with following columns


empno,ename,salary
2.create a procedure EmpProcedure in mysql
3.insert the data into employee table using Callable interface
using procedure EmpProcedure

Solution:
1.Table Creation:
create table Empjdbc(empno int primary key,ename varchar(20),salary float);

2.Procedure creation: (procedure-It is a


block of statement which contains multiple quiries
DELIMITER // without procedure
also we can write but in the question it is mentioned
create PROCEDURE p1(in empno int, ename varchar(20),salary float) and we
can have multiple quries in the procedure so we can use it in a easy way)
BEGIN
insert into Empjdbc values(empno,ename,salary); (DELIMITER-
used to seperate individual sql statements within a script or batch
END// used to creating
stored procedures and triggers,uses of delimeter in sql 1.Statement seperation
DELIMITER ; 2.Batch execution-when
executing multiple sql stmnts it is crucial to distinguis 1 stmnt to other
3.Stored procedure and
triggers--to mark end of a block of sql stmnt.)
select * from Empjdbc;

JDBC Program:

package p1.JDBCFinal;
import java.sql.*;
(1.importing package)
public class App
{
public static void main(String[] args) throws Exception (main function)
(throws -- it throwsthe exception or we can use try catch)
{
String query ="CALL p1(?,?,?)"; (calling the
procedure query ? is used because we need a multiple values so we cannot declare
any )
int[] empno = {101,102,103,104,105};
String[] ename = {"keerthi","krishna","vedasai","karuna","geeta"};
double[] salary = {32500,34060,35600,37070,38850};
Class.forName("com.mysql.jdbc.Driver");
(2.Load/Register the driver, load=for name)
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/Keerthi","root","Root123$"
); (3.create connection)(con is a interface we need to search for
the method and the method is getconnection which will give us the instance of
connection)
CallableStatement cs = con.prepareCall(query);
(4.Creating a statement)
int k=0; ( used because while executing
it takes many times the repeated
for (int i=0; i<empno.length; i++) output so by using for loop it
can have the rows calculated in it)
{
cs.setInt(1, empno[i]);

cs.setString(2,ename[i]);
cs.setDouble(3, salary[i]);
cs.executeUpdate();
(5.Execute quaries)
k++;
}
System.out.println(k+ " rows are effected:");
(6.Process Result)
cs.close();
(7.closing connection)
con.close(); }
}

OUTPUT:
int k =0; is initialized outside the loop to keep track of the number of
iterations or updates within the loop)
(k++; is then used to incement the value of 'k' after each iteration of the loop)
(For loop is used to iterate over an array named empnon)
(For loop - it executes the statment of the program several times and we know tha
exact num of iterations to be done in for loop)
(while loop - we dont know the exact num of iterations)
(why for why not while--The forloop is well suited for iterating over a range of
values
(we can acheive with wile loop also but it might require additional lines of code
for initializing and iteraton
so for loop is often prefferd when the iteration involves a known range or
sequence,as in this case)

You might also like