Add

Jdbc Program that gives Employee Details based on the given department number.

11:15:00 PM Rohit Kumar Verma 0 Comments

Requisite:
Oracle: Any version , Tested on Oracle 12c.
Java 64 bit: Tested on version 7.0, from 8.0 JDBC Driver removed.





//SelectInputQuery.java
/*  Program to get department number from the user and process according to it
*/

import java.sql.*;
import java.util.*;
public class SelectInputQuery
{
public static void main(String[] args) throws Exception
{
//Registering jdbc driver
sun.jdbc.odbc.JdbcOdbcDriver obj = new sun.jdbc.odbc.JdbcOdbcDriver();
DriverManager.registerDriver(obj);
//Creating connection
Connection con = DriverManager.getConnection("jdbc:odbc:oradsn","c##scott","tiger");
//Creating select statement
Statement st = con.createStatement();
//Requesting query form the user
Scanner sc = new Scanner(System.in);
System.out.println("Enter Department no :");
String qry = sc.next();

//Passing query to database and processing it
ResultSet rs = st.executeQuery("Select * from emp where deptno ="+qry);
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "+rs.getString(4)+" "+rs.getString(5));
}
rs.close(); // closing resultset
st.close(); //closing statement
con.close(); // closing connection
}// main
}// class

0 comments: