• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

callable statement problem

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pl/sql function......is
create or replace function getAnnsal(e_no in emp.empno%type)
return number
is
sal1 emp.sal%type:=0;
asal emp.sal%type:=0;
begin
select sal into asal from emp
where empno=e_no;
if sql%found then
sal1:=asal*12;
return sal1;
else
return -1;
end if;
end getAnnsal;

here we calculate the annual salary.........through java jdbc .....
the progam is...
import java.io.*;
import java.sql.*;
class javademo
{
public static void main(String[] args)throws SQLException,IOException,ClassNotFoundException
{
int eno;
//String ename;
Connection conn=null;
CallableStatement stmt=null;


try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver load");
conn=DriverManager.getConnection("jdbc:odbc:Emp","scott","tiger");
//DataInputStream dis=new DataInputStream(System.in);
BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));


stmt=conn.prepareCall("{=? call emp.getAnnsal(?)}");
System.out.println("enter the no");
eno=Integer.parseInt(dis.readLine());
//stmt.setString(empno);
System.out.println(eno);

stmt.execute();
double vsal=stmt.getDouble("sal");
if(vsal==-1)
{
System.out.println("emp does not exist");
}
else
{
System.out.println("Annual sal"+vsal);

}
stmt.close();
conn.close();
}catch(ClassNotFoundException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(NumberFormatException e)
{
e.printStackTrace();
}

}
}

and it will give the following exception error...
Driver load
enter the no
12
java.lang.NumberFormatException: For input string: "enter the no"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:66)
at java.lang.Integer.parseInt(Integer.java:485)
at java.lang.Integer.parseInt(Integer.java:520)
at javademo.main(Javademo2.java:24)

Process completed.
can you please check that program and remove what problem it have....
 
Bartender
Posts: 2658
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Arun, welcome to JavaRanch.
Can you please use code tags?
You can edit your post by clicking on the Edit icon at its right top.

Regards, Jan
 
I just had the craziest dream. This tiny ad was in it.
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic