I have the following code which calls a stored procedure from the Java database. Even though my class is public i get an error saying ....The class 'WorkPlace_Seat_Allocation' does not exist or is inaccessible. This can happen if the class is not public.
BUILD SUCCESSFUL (total time: 0 seconds)
package workplace_seat_allocation;
import java.sql.*;
public class WorkPlace_Seat_Allocation {
public static void main(String[] args) {
View_All_Seats();
}
public static Connection getConnection(){
Connection con=null;
try{
String host = "jdbc:derby://localhost:1527/SeatAllocation";
String uName = "SeatAllocation";
String Password = "sandy";
con = DriverManager.getConnection(host, uName, Password);
}
catch(SQLException e){
System.out.println(e.getMessage());
}
return con;
}
public static void View_All_Seats(){
Connection con =getConnection();
CallableStatement cs =null;
ResultSet rs = null;
try {
cs = con.prepareCall("{call GetAllSeatS(?,?,?)}");
cs.registerOutParameter(1,Types.VARCHAR);
cs.execute();
rs = (ResultSet) cs.getObject(1);
while(rs.next()){
System.out.println(rs.getString(1)+" "+ rs.getString(2)+ " "+ rs.getString(3));
}
con.close();
}
catch(SQLException e){
System.out.println(e.getMessage());
}
}
}
and here is the stored procedure
CREATE PROCEDURE GetAllSeatS(OUT sid varchar(5), out loc varchar(15), OUT ext char(4))
PARAMETER STYLE JAVA READS SQL DATA LANGUAGE JAVA EXTERNAL NAME
--"SELECT SEATID, LOCATION, EXTENSION from seat"
'WorkPlace_Seat_Allocation.View_All_Seats';
解决方案
I think you need to fully qualify the class name with it's package name.
Try changing
CREATE PROCEDURE GetAllSeatS(OUT sid varchar(5), out loc varchar(15), OUT ext char(4))
PARAMETER STYLE JAVA READS SQL DATA LANGUAGE JAVA EXTERNAL NAME
--"SELECT SEATID, LOCATION, EXTENSION from seat"
'WorkPlace_Seat_Allocation.View_All_Seats';
to
CREATE PROCEDURE GetAllSeatS(OUT sid varchar(5), out loc varchar(15), OUT ext char(4))
PARAMETER STYLE JAVA READS SQL DATA LANGUAGE JAVA EXTERNAL NAME
--"SELECT SEATID, LOCATION, EXTENSION from seat"
'workplace_seat_allocation.WorkPlace_Seat_Allocation.View_All_Seats';
Hope this helps,
Fredrik