aspose file tools*
The moose likes JDBC and the fly likes callable statement problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "callable statement problem" Watch "callable statement problem" New topic
Author

callable statement problem

arun kumar tripathi
Greenhorn

Joined: Mar 24, 2010
Posts: 2
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

Joined: Dec 20, 2006
Posts: 2499
    
    8

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


OCUP UML fundamental and ITIL foundation
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: callable statement problem