Java,Derby:“ CREATE_TYPE”出现问题声明 [英] Derby, Java: Trouble with "CREATE_TYPE" statement

查看:63
本文介绍了Java,Derby:“ CREATE_TYPE”出现问题声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在Eclipse中弄乱Apache Derby。我已经启动了网络服务器,并且一直在使用servlet。在我的Eclipse项目中,程序包 base.pack中有一个名为 User的类。我打开了一个SQL脚本,并且一直在尝试将实现Serializable的User转换为自定义类型。当我运行以下行时,一切正常:

 创建类型CARTEBLANCHE.bee 
外部名称'base.pack用户'
语言JAVA

这遵循他们在此处标识的一般格式: http://db.apache.org/derby/docs/10.7/ref/ rrefsqljcreatetype.html#rrefsqljcreatetype



现在,当我尝试使用这种新类型创建表时,出现错误。我运行以下行:

 创建表CARTEBLANCHE.TestTabel(ID整数不为空,名称CARTEBLANCHE.bee,主键(ID )); 

我收到以下错误:


列 NAME的类 base.pack.User不存在或不可访问。如果班级不是公开的,则可能发生这种情况。


现在,该班级实际上是公开的,正如我之前指出的,实现Serializable。我认为我输入的包裹名称不正确,但我可能是错的。我想知道,这是我的课程路径问题吗?如果是这样,您如何建议我解决此问题?我承认我对类路径不太了解。



谢谢。



(仅供参考,我已将我的项目构建路径配置为包括 derby.jar derbyclient.jar derbytools。 jar derbynet.jar ,然后将这些文件放入项目的 lib

解决方案

尽我所能,我建议如果您对Java的CLASSPATH概念不满意,那么在Derby中编写自己的自定义数据类型可能是一个具有挑战性的项目吗?



在这里描述的特定情况下,将会出现的一个问题是,自定义Java代码不仅必须对客户端应用程序可用,而且还必须对Derby可用。网络服务器,这意味着您将需要修改服务器的CLASSPATH以及应用程序的CLASSPATH。



这是有可能的,这不是一个初学者级的项目。 / p>

要开始自定义Derby Network Server,第一个主题涉及如何启动它。以下是一般过程的概述: http://db.apache.org /derby/docs/10.11/adminguide/tadmincbdjhhfd.html



根据您启动Derby Network Server的精度,您可能会编辑在 startNetworkServer startNetworkServer.bat 脚本中设置CLASSPATH,否则您将在自己的脚本中编辑CLASSPATH设置



如果它是诸如Eclipse或Netbeans之类的工具,正在启动Derby Network Server,则需要深入研究以下内容:



如果您已经编写了一个自定义Java应用程序来启动Derby Network Server(例如,如下所述: http://db.apache.org/derby/docs/10 .11 / adminguide / tadminconfig814963.html ),那么您将配置自定义应用程序的CLASSPATH。



无论如何,作为基本步骤,您想要在Derby Network Server的类路径中部署自定义Java扩展类,这意味着您需要将它们构建到.jar文件中,并将该.jar文件放在Derby Network Server可以访问的位置,以及您将希望使构建一个jar并将其复制到正确位置的过程变得简单,因此您应该将其集成到正在使用的任何构建工具中(Apache Ant?)。



而且,您需要考虑Java安全策略,因为默认的安全策略将阻止您将自定义Java类简单地加载到Derby Network Server中,因为这看起来像一个恶意软件攻击,Derby Network Server将尝试阻止这种情况。因此,请研究安全手册的这一部分: http://db.apache。 org / derby / docs / 10.11 / security / tsecnetservrun.html


I've been messing around with Apache Derby inside Eclipse. I've booted up a Network Server, and I've been working with servlets. In my Eclipse project, I have a class called "User", inside the package "base.pack". I have an SQL script open, and I've been trying to convert User, which implements Serializable, into a custom type. When I run the following lines, everything works fine:

CREATE TYPE CARTEBLANCHE.bee
EXTERNAL NAME 'base.pack.User'
LANGUAGE JAVA

This follows the general format they identify here: http://db.apache.org/derby/docs/10.7/ref/rrefsqljcreatetype.html#rrefsqljcreatetype

Now, when I try to create a table using this new type, I get an error. I run the following line:

CREATE TABLE CARTEBLANCHE.TestTabel (ID INTEGER NOT NULL, NAME CARTEBLANCHE.bee, PRIMARY KEY(ID));

And I receive the following error:

The class 'base.pack.User' for column 'NAME' does not exist or is inaccessible. This can happen if the class is not public.

Now, the class is in fact public, and as I noted before, it does implement Serializable. I don't think I'm stating the package name incorrectly, but I could be wrong. I'm wondering, is this an issue with my classpath? If so, how would you suggest I fix this? I admit that I do not know much about the classpath.

Thank you.

(For reference, I have configured my project build path to include derby.jar, derbyclient.jar, derbytools.jar, and derbynet.jar, and I have put these files into my project's lib folder as well).

解决方案

As politely as I can, may I suggest that if you are uncomfortable with Java's CLASSPATH notion, then writing your own custom data types in Derby is likely to be a challenging project?

In the specific case you describe here, one issue that will arise is that your custom Java code has to be available not only to your client application, but also to the Derby Network Server, which means you will need to be modifying the server's CLASSPATH as well as your application's CLASSPATH.

It's all possible, it's just not a beginner-level project.

To get started with customizing your Derby Network Server, the first topic involves how you are starting it. Here's an overview of the general process: http://db.apache.org/derby/docs/10.11/adminguide/tadmincbdjhhfd.html

Depending on how precisely you are starting the Derby Network Server, you'll possibly be editing the CLASSPATH settting in the startNetworkServer or startNetworkServer.bat script, or you'll be editing the CLASSPATH setting in your own script that you have written to start the server.

If it's a tool like Eclipse or Netbeans which is starting the Derby Network Server, you'll need to dig into the details of that tool to learn more about how to configure its CLASSPATH.

And if you've written a custom Java application to start the Derby Network Server (e.g., as described here: http://db.apache.org/derby/docs/10.11/adminguide/tadminconfig814963.html) then you'd be configuring the CLASSPATH of your custom application.

Regardless, as a basic step, you're going to want to be deploying your custom Java extension classes in the Derby Network Server's classpath, which means you'll want to build them into a .jar file and put that .jar file somewhere that the Derby Network Server has access to, and you'll want to make that build-a-jar-and-copy-it-to-the-right-location process straightforward, so you should integrate it into whatever build tool you're using (Apache Ant?).

And, you'll need to consider Java security policy, because the default security policy will prevent you from trivially loading custom Java classes into your Derby Network Server as that would seem like a malware attack and the Derby Network Server is going to try to prevent that. So study this section of the Security manual: http://db.apache.org/derby/docs/10.11/security/tsecnetservrun.html

这篇关于Java,Derby:“ CREATE_TYPE”出现问题声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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