package ddrs;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;
public class RetrieveDataBaseServ extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) {
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con = DriverManager.getConnection("oracle:jdbc:thin:@localhost:1521: Hanuman " , "scott " , "tiger ");
Statement st = con.createStatement(); ResultSet rs = st.executeQuery("select * from emp");
while (rs.next()) {
pw.println(rs.getString(1) + " " + rs.getString(2));
}
} catch (Exception e) {
res.sendError(504, "PROBLEM IN SERVLET...");
}
}
}
web.xml:
<web-app>
<servlet>
<servlet-name>Babu</servlet-name>
<serclet-class>ddrs.RetrieveDataBaseServ</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Babu</servlet-name>
<url-pattern>Dinesh</url-pattern>
</servlet-mapping>
</web-app>
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;
public class RetrieveDataBaseServ extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) {
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con = DriverManager.getConnection("oracle:jdbc:thin:@localhost:1521: Hanuman " , "scott " , "tiger ");
Statement st = con.createStatement(); ResultSet rs = st.executeQuery("select * from emp");
while (rs.next()) {
pw.println(rs.getString(1) + " " + rs.getString(2));
}
} catch (Exception e) {
res.sendError(504, "PROBLEM IN SERVLET...");
}
}
}
web.xml:
<web-app>
<servlet>
<servlet-name>Babu</servlet-name>
<serclet-class>ddrs.RetrieveDataBaseServ</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Babu</servlet-name>
<url-pattern>Dinesh</url-pattern>
</servlet-mapping>
</web-app>
package ds;
import javax.servlet.*;
import java.io.*;
import java.util.*;
public class DateServ extends GenericServlet {
public DateServ() {
System.out.println("SERVLET LOADED...");
}
public void init() {
System.out.println("I AM FROM init METHOD...");
}
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
Date d = new Date();
String s = d.toString();
pw.println("<h1> WELCOME TO SERVLETS <h1>");
pw.println("<h2> CURRENT DATE & TIME IS : " + s + "<h2>");
}
public void destroy() {
System.out.println("I AM FROM destroy METHOD...");
}
}
web.xml:
<web-app>
<servlet>
<servlet-name>kalyan</servlet-name>
<servlet-class>ds.DateServ</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>kalyan</servlet-name>
<url-pattern>/suman</url-pattern>
</servlet-mapping>
</web-app>
import javax.servlet.*;
import java.io.*;
import java.util.*;
public class DateServ extends GenericServlet {
public DateServ() {
System.out.println("SERVLET LOADED...");
}
public void init() {
System.out.println("I AM FROM init METHOD...");
}
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
Date d = new Date();
String s = d.toString();
pw.println("<h1> WELCOME TO SERVLETS <h1>");
pw.println("<h2> CURRENT DATE & TIME IS : " + s + "<h2>");
}
public void destroy() {
System.out.println("I AM FROM destroy METHOD...");
}
}
web.xml:
<web-app>
<servlet>
<servlet-name>kalyan</servlet-name>
<servlet-class>ds.DateServ</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>kalyan</servlet-name>
<url-pattern>/suman</url-pattern>
</servlet-mapping>
</web-app>
import javax.servlet.*;
import java.io.*;
public class First extends GenericServlet {
public First() {
System.out.println("I AM FROM DEFAULT CONSTRUCTOR...");
}
public void init() {
System.out.println("I AM FROM init METHOD...");
}
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
System.out.println("I LOVE MY MOM...");
System.out.println("I AM FROM service METHOD...");
}
public void destroy() {
System.out.println("I AM FROM destroy METHOD...");
}
}
import java.io.*;
public class First extends GenericServlet {
public First() {
System.out.println("I AM FROM DEFAULT CONSTRUCTOR...");
}
public void init() {
System.out.println("I AM FROM init METHOD...");
}
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
System.out.println("I LOVE MY MOM...");
System.out.println("I AM FROM service METHOD...");
}
public void destroy() {
System.out.println("I AM FROM destroy METHOD...");
}
}
1- Introduction
2- OOPS
3- Interfaces
4- Packages
5- java.lang.String
6- Wrapper classes
7- Java.io
8- Exception Handling
9- MultiThreading
10- Nested classes
11- Enumaration & GC
12- Collections
13- Java.net
14- Java.awt
15- Swings
16- JVM
2- OOPS
3- Interfaces
4- Packages
5- java.lang.String
6- Wrapper classes
7- Java.io
8- Exception Handling
9- MultiThreading
10- Nested classes
11- Enumaration & GC
12- Collections
13- Java.net
14- Java.awt
15- Swings
16- JVM
import java.sql.*;
class CreateTable {
public static void main(String[] args) {
try {
Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
System.out.println("CONNECTION ESTABLISHED...");
Statement st = con.createStatement();
int i = st.executeUpdate("create table kalyan (eno number (4), ename varchar2 (15))");
System.out.println("TABLE CREATED...");
con.close();
} catch (Exception e) {
e.printStackTrace();
}
} // main
} // CreateTable
class CreateTable {
public static void main(String[] args) {
try {
Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
System.out.println("CONNECTION ESTABLISHED...");
Statement st = con.createStatement();
int i = st.executeUpdate("create table kalyan (eno number (4), ename varchar2 (15))");
System.out.println("TABLE CREATED...");
con.close();
} catch (Exception e) {
e.printStackTrace();
}
} // main
} // CreateTable
import java.sql.*;
class BatchProConcept {
public static void main(String[] args) throws Exception {
Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
System.out.println("CONNECTION ESTABLISHED...");
con.setAutoCommit(false);
Statement st = con.createStatement();
st.addBatch("insert into student values (3, 'j2ee')");
st.addBatch("delete from student where sno=1");
st.addBatch("update student set sname='java' where sno=2");
int res[] = st.executeBatch();
for (int i = 0; i < res.length; i++) {
System.out.println("NUMBER OF ROWS EFFECTED : " + res[i]);
}
con.commit();
con.rollback();
con.close();
} // main
} // BatchProConcept
class BatchProConcept {
public static void main(String[] args) throws Exception {
Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
System.out.println("CONNECTION ESTABLISHED...");
con.setAutoCommit(false);
Statement st = con.createStatement();
st.addBatch("insert into student values (3, 'j2ee')");
st.addBatch("delete from student where sno=1");
st.addBatch("update student set sname='java' where sno=2");
int res[] = st.executeBatch();
for (int i = 0; i < res.length; i++) {
System.out.println("NUMBER OF ROWS EFFECTED : " + res[i]);
}
con.commit();
con.rollback();
con.close();
} // main
} // BatchProConcept
import java.sql.*;
class UpdateResultSet {
public static void main(String[] args) {
try {
Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
System.out.println("CONNECTION ESTABLISHED...");
Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = st.executeQuery("select * from emp1");
rs.next();
rs.updateInt(2, 8000);
rs.updateRow();
System.out.println("1 ROW UPDATED...");
rs.moveToInsertRow();
rs.updateInt(1, 104);
rs.updateInt(2, 2000);
rs.insertRow();
System.out.println("1 ROW INSERTED...");
rs.absolute(2);
rs.deleteRow();
System.out.println("1 ROW DELETED...");
con.close();
} catch (Exception e) {
e.printStackTrace();
}
} // main
} // UpdateResultSet
class UpdateResultSet {
public static void main(String[] args) {
try {
Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
System.out.println("CONNECTION ESTABLISHED...");
Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = st.executeQuery("select * from emp1");
rs.next();
rs.updateInt(2, 8000);
rs.updateRow();
System.out.println("1 ROW UPDATED...");
rs.moveToInsertRow();
rs.updateInt(1, 104);
rs.updateInt(2, 2000);
rs.insertRow();
System.out.println("1 ROW INSERTED...");
rs.absolute(2);
rs.deleteRow();
System.out.println("1 ROW DELETED...");
con.close();
} catch (Exception e) {
e.printStackTrace();
}
} // main
} // UpdateResultSet
import java.sql.*;
class ScrollResultSet {
public static void main(String[] args) {
try {
Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
System.out.println("CONNECTION ESTABLISHED...");
Statement st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = st.executeQuery("select * from emp");
System.out.println("RECORDS IN THE TABLE...");
while (rs.next()) {
System.out.println(rs.getInt(1) + " " + rs.getString(2));
}
rs.first();
System.out.println("FIRST RECORD...");
System.out.println(rs.getInt(1) + " " + rs.getString(2));
rs.absolute(3);
System.out.println("THIRD RECORD...");
System.out.println(rs.getInt(1) + " " + rs.getString(2));
rs.last();
System.out.println("LAST RECORD...");
System.out.println(rs.getInt(1) + " " + rs.getString(2));
rs.previous();
rs.relative(-1);
System.out.println("FIRST RECORD...");
System.out.println(rs.getInt(1) + " " + rs.getString(2));
con.close();
} catch (Exception e) {
System.out.println(e);
}
} // main
}; // ScrollResultSet
class ScrollResultSet {
public static void main(String[] args) {
try {
Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
System.out.println("CONNECTION ESTABLISHED...");
Statement st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = st.executeQuery("select * from emp");
System.out.println("RECORDS IN THE TABLE...");
while (rs.next()) {
System.out.println(rs.getInt(1) + " " + rs.getString(2));
}
rs.first();
System.out.println("FIRST RECORD...");
System.out.println(rs.getInt(1) + " " + rs.getString(2));
rs.absolute(3);
System.out.println("THIRD RECORD...");
System.out.println(rs.getInt(1) + " " + rs.getString(2));
rs.last();
System.out.println("LAST RECORD...");
System.out.println(rs.getInt(1) + " " + rs.getString(2));
rs.previous();
rs.relative(-1);
System.out.println("FIRST RECORD...");
System.out.println(rs.getInt(1) + " " + rs.getString(2));
con.close();
} catch (Exception e) {
System.out.println(e);
}
} // main
}; // ScrollResultSet
import java.sql.*;
import java.io.*;
import java.util.*;
class RBFConcept {
public static void main(String[] args) {
try {
FileInputStream fis = new FileInputStream("rbfdb.prop");
Properties p = new Properties();
p.load(fis);
String dname = (String) p.get("Dname");
String url = (String) p.get("URL");
String username = (String) p.get("Uname");
String password = (String) p.get("Pwd");
String tablename = (String) p.get("Tablename");
// loading drivers and obtaining connection
Class.forName(dname);
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection(url, username, password);
System.out.println("CONNECTION CREATED...");
// executing query
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from" + tablename);
ResultSetMetaData rsmd = rs.getMetaData();
// printing column names
System.out.println("=================================");
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
System.out.print(rsmd.getColumnName(i) + " ");
}
System.out.println("");
System.out.println("=================================");
// printing the data
while (rs.next()) {
for (int j = 1; j <= rsmd.getColumnCount(); j++) {
System.out.print(rs.getString(j) + " ");
}
}
con.close();
} catch (Exception e) {
e.printStackTrace();
}
} // main
} // RSFConcept
import java.io.*;
import java.util.*;
class RBFConcept {
public static void main(String[] args) {
try {
FileInputStream fis = new FileInputStream("rbfdb.prop");
Properties p = new Properties();
p.load(fis);
String dname = (String) p.get("Dname");
String url = (String) p.get("URL");
String username = (String) p.get("Uname");
String password = (String) p.get("Pwd");
String tablename = (String) p.get("Tablename");
// loading drivers and obtaining connection
Class.forName(dname);
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection(url, username, password);
System.out.println("CONNECTION CREATED...");
// executing query
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from" + tablename);
ResultSetMetaData rsmd = rs.getMetaData();
// printing column names
System.out.println("=================================");
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
System.out.print(rsmd.getColumnName(i) + " ");
}
System.out.println("");
System.out.println("=================================");
// printing the data
while (rs.next()) {
for (int j = 1; j <= rsmd.getColumnCount(); j++) {
System.out.print(rs.getString(j) + " ");
}
}
con.close();
} catch (Exception e) {
e.printStackTrace();
}
} // main
} // RSFConcept
import java.sql.*;
class Table {
public static void main(String[] args) {
try {
DriverManager.registerDriver(new Sun.jdbc.odbc.JdbcOdbcDriver());
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
System.out.println("CONNECTION ESTABLISHED...");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from dept");
ResultSetMetaData rsmd = rs.getMetaData();
System.out.println("===========================================");
// PRINTING COLUMN NAME
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
System.out.print(rsmd.getColumnName(i) + " ");
}
System.out.println("");
System.out.println("==========================================");
// PRINTING THE DATA OF THE TABLE
while (rs.next()) {
for (int j = 1; j <= rsmd.getColumnCount(); j++) {
System.out.print(rs.getString(j) + " ");
}
System.out.println("");
}
con.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
}
} // main
}; // Table
class Table {
public static void main(String[] args) {
try {
DriverManager.registerDriver(new Sun.jdbc.odbc.JdbcOdbcDriver());
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
System.out.println("CONNECTION ESTABLISHED...");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from dept");
ResultSetMetaData rsmd = rs.getMetaData();
System.out.println("===========================================");
// PRINTING COLUMN NAME
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
System.out.print(rsmd.getColumnName(i) + " ");
}
System.out.println("");
System.out.println("==========================================");
// PRINTING THE DATA OF THE TABLE
while (rs.next()) {
for (int j = 1; j <= rsmd.getColumnCount(); j++) {
System.out.print(rs.getString(j) + " ");
}
System.out.println("");
}
con.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
}
} // main
}; // Table
import java.sql.*;
class MetaData {
public static void main(String[] args) {
try {
DriverManager.registerDriver(new Sun.jdbc.odbc.JdbcOdbcDriver());
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc : odbc : oradsn", "scott", "tiger");
System.out.println("CONNECTION ESTABLISHED...");
// UNIVERSAL DATABASE DETAILS
DatabaseMetaData dmd = con.getMetaData();
System.out.println("DATABASE NAME : " + dmd.getDatabaseProductName());
System.out.println("DATABASE VERSION : " + dmd.getDatabaseProductVersion());
System.out.println("NAME OF THE DRIVER : " + dmd.getDriverName());
System.out.println("VERSION OF THE DRIVER : " + dmd.getDriverVersion());
System.out.println("MAJOR VERSION OF DRIVER : " + dmd.getDriverMajorVersion());
System.out.println("MINOR VERSION OF DRIVER : " + dmd.getDriverMinorVersion());
// USER DATABASE DETAILS
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from dept");
ResultSetMetaData rsmd = rs.getMetaData();
System.out.println("NUMBER OF COLUMNS : " + rsmd.getColumnCount());
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
System.out.println("NAME OF THE COLUMN : " + rsmd.getColumnName(i));
System.out.println("TYPE OF THE COLUMN : " + rsmd.getColumnType(i));
}
con.close();
} catch (Exception e) {
e.printStackTrace();
}
} // main
} // MetaData
class MetaData {
public static void main(String[] args) {
try {
DriverManager.registerDriver(new Sun.jdbc.odbc.JdbcOdbcDriver());
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc : odbc : oradsn", "scott", "tiger");
System.out.println("CONNECTION ESTABLISHED...");
// UNIVERSAL DATABASE DETAILS
DatabaseMetaData dmd = con.getMetaData();
System.out.println("DATABASE NAME : " + dmd.getDatabaseProductName());
System.out.println("DATABASE VERSION : " + dmd.getDatabaseProductVersion());
System.out.println("NAME OF THE DRIVER : " + dmd.getDriverName());
System.out.println("VERSION OF THE DRIVER : " + dmd.getDriverVersion());
System.out.println("MAJOR VERSION OF DRIVER : " + dmd.getDriverMajorVersion());
System.out.println("MINOR VERSION OF DRIVER : " + dmd.getDriverMinorVersion());
// USER DATABASE DETAILS
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from dept");
ResultSetMetaData rsmd = rs.getMetaData();
System.out.println("NUMBER OF COLUMNS : " + rsmd.getColumnCount());
for (int i = 1; i <= rsmd.getColumnCount(); i++) {
System.out.println("NAME OF THE COLUMN : " + rsmd.getColumnName(i));
System.out.println("TYPE OF THE COLUMN : " + rsmd.getColumnType(i));
}
con.close();
} catch (Exception e) {
e.printStackTrace();
}
} // main
} // MetaData
import java.sql.*;
class XSelect {
public static void main(String[] args) {
try {
DriverManager.registerDriver(new
Sun.jdbc.odbc.JdbcOdbcDriver());
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:odbc:xldsn");
System.out.println("CONNECTION ESTABLISHED...");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from [student$]");
while (rs.next()) {
System.out.println(rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3));
}
con.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
}
} // main
} // XSelect
class XSelect {
public static void main(String[] args) {
try {
DriverManager.registerDriver(new
Sun.jdbc.odbc.JdbcOdbcDriver());
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:odbc:xldsn");
System.out.println("CONNECTION ESTABLISHED...");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from [student$]");
while (rs.next()) {
System.out.println(rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3));
}
con.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
}
} // main
} // XSelect
create or replace procedure StuPro
(no in number, name in varchar2, loc1 out varchar2)
as
begin
select dname, loc into name, loc1 from dept
where deptno=no;
insert int abc values (no, name, loc1);
end;
import java.sql.*;
import java.io.*;
class ProConcept {
public static void main(String[] args) {
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:
BudDinu ","scott ","tiger ");
DataInputStream dis = new DataInputStream(System.in);
System.out.println("ENTER DEPARTMENT NUMBER : ");
String s1 = dis.readLine();
int n1 = Integer.parseInt(s1);
CallableStatement cs = con.prepareCall("{call StuPro (?,?,?)}");
cs.setInt(1, n1);
cs.registerOutParameter(2, Types.VARCHAR);
cs.registerOutParameter(3, Types.VARCHAR);
cs.execute();
String res = cs.getString(2);
String res1 = cs.getString(3);
System.out.println("DEPARTMENT NAME : " + res);
System.out.println("DEPARTMENT LOCATION : " + res1);
} catch (Exception e) {
System.out.println(e);
}
} // main
} // ProConcept
(no in number, name in varchar2, loc1 out varchar2)
as
begin
select dname, loc into name, loc1 from dept
where deptno=no;
insert int abc values (no, name, loc1);
end;
import java.sql.*;
import java.io.*;
class ProConcept {
public static void main(String[] args) {
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:
BudDinu ","scott ","tiger ");
DataInputStream dis = new DataInputStream(System.in);
System.out.println("ENTER DEPARTMENT NUMBER : ");
String s1 = dis.readLine();
int n1 = Integer.parseInt(s1);
CallableStatement cs = con.prepareCall("{call StuPro (?,?,?)}");
cs.setInt(1, n1);
cs.registerOutParameter(2, Types.VARCHAR);
cs.registerOutParameter(3, Types.VARCHAR);
cs.execute();
String res = cs.getString(2);
String res1 = cs.getString(3);
System.out.println("DEPARTMENT NAME : " + res);
System.out.println("DEPARTMENT LOCATION : " + res1);
} catch (Exception e) {
System.out.println(e);
}
} // main
} // ProConcept
create or replace function StuFun(a in number, b in number, n1 out number)
return number as n2 number;
begin
n1:=a*b;
n2:=a+b;
return (n2);
end;
import java.sql.*;
import java.io.*;
class FunConcept {
public static void main(String[] args) {
try {
DriverManager.registerDriver(new
oracle.jdbc.driver.OracleDriver());
System.out.println("DRIVERS LOADED...");
Connection con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:
BudDinu " , "scott " , "tiger ");
System.out.println("CONNECTION OBTAINED...");
DataInputStream dis = new DataInputStream(System.in);
System.out.println("ENTER FIRST NUMBER : ");
String s1 = dis.readLine();
System.out.println("ENTER SECOND NUMBER : ");
String s2 = dis.readLine();
int n1 = Integer.parseInt(s1);
int n2 = Integer.parseInt(s2);
CallableStatement cs = con.prepareCall("{?=call ArthFun (?,?,?)}");
cs.setInt(2, n1);
cs.setInt(3, n2);
cs.registerOutParameter(1, Types.INTEGER);
cs.registerOutParameter(4, Types.INTEGER);
cs.execute();
int res = cs.getInt(1);
int res1 = cs.getInt(4);
System.out.println("SUM OF THE NUMBERS : " + res);
System.out.println("MULTIPLICATION OF THE NUMBERS : " + res1);
} catch (Exception e) {
e.printStackTrace();
}
} // main
} // FunConcept