Java错误:类不存在或无法访问 [英] Java error : class does not exist or it is inaccessible

查看:169
本文介绍了Java错误:类不存在或无法访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码从Java数据库调用存储过程。即使我的班级是公开的,我也会收到一个错误说明....



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';

推荐答案

我认为您需要完全符合条件带有包名的类名。

尝试changi ng $>
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


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';





希望这会有所帮助,

Fredrik



Hope this helps,
Fredrik


请参阅 http:// docs.oracle.com/javase/tutorial/jdbc/basics/storedprocedures.html#creating_stored_procedures_java_db [ ^ ],供指导o n使用存储过程。
See http://docs.oracle.com/javase/tutorial/jdbc/basics/storedprocedures.html#creating_stored_procedures_java_db[^], for guidance on using stored procedures.


这篇关于Java错误:类不存在或无法访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆