• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

callable statement problem

 
arun kumar tripathi
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("jdbcdbc: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....
 
Jan Cumps
Bartender
Posts: 2608
14
C++ Linux Netbeans IDE
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic