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

11:15:00 PM Rohit Kumar Verma 0 Comments

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

/*  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();
//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.out.println("Enter Department no :");
String qry =;

//Passing query to database and processing it
ResultSet rs = st.executeQuery("Select * from emp where deptno ="+qry);
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