gpt4 book ai didi

java - 如何创建 Java 包以及如何将它们导入到另一个包中?

转载 作者:行者123 更新时间:2023-12-02 11:50:00 25 4
gpt4 key购买 nike

我是java新手,我试图从另一个包导入包,但另一个包无法编译,因为它说它找不到第一个包,这就是我所做的:

第一个包代码:

package sagar.sql;

import java.sql.Connection;
import java.sql.SQLException;

import oracle.apps.bne.exception.BneException;
import oracle.apps.bne.framework.BneWebAppsContext;
import oracle.apps.bne.utilities.sql.BneBaseSQL;

public class SagarSupplierSiteNameSQL extends BneBaseSQL {
public SagarSupplierSiteNameSQL(BneWebAppsContext paramBneWebAppsContext,
String paramString) throws SQLException,
BneException {
Connection connection = paramBneWebAppsContext.getJDBCConnection();
StringBuffer stringBuffer = new StringBuffer();

stringBuffer.append("SELECT PARTY_NAME,ACCOUNT_NUMBER,LOCATION WHERE org_id = 281 AND ACCOUNT_NUMBER = :1");


if ((paramString != null) && (!paramString.trim().equals(""))) {
stringBuffer.append("AND " + paramString);
}

//stringBuffer.append(" ORDER BY VENDOR_SITE_CODE, ADDRESS ");

setQuery(connection, stringBuffer.toString());
}
}

第二包代码:

package sagar.validator;


import java.util.Hashtable;

import oracle.apps.bne.exception.BneException;
import oracle.apps.bne.exception.BneFatalException;
import oracle.apps.bne.exception.BneMissingParameterException;
import oracle.apps.bne.framework.BneWebAppsContext;
import oracle.apps.bne.integrator.validators.BneUploadValidator;
import oracle.apps.bne.utilities.sql.BneCompositeSQLCriteria;
import oracle.apps.bne.utilities.sql.BneResultSet;
import oracle.apps.bne.utilities.sql.BneSQLStatement;

import sagar.sql.SagarSupplierSiteNameSQL;

public class SagarSupplierSiteNameValidator extends BneUploadValidator {

public String[] getDomainParameters() {
return new String[] { "P_CUST_NUM" };
}

public BneResultSet getDomainValues(BneWebAppsContext paramBneWebAppsContext,
Hashtable paramHashtable,
BneCompositeSQLCriteria paramBneCompositeSQLCriteria) throws BneException {

SagarSupplierSiteNameSQL sagarSupplierSiteNameSQL = null;
BneResultSet bneResultSet = null;
BneSQLStatement bneSQLStatement1 = new BneSQLStatement();

if (paramBneCompositeSQLCriteria != null) {
bneSQLStatement1 =
paramBneCompositeSQLCriteria.evaluate(bneSQLStatement1);
}

String str1 = (String)paramHashtable.get("P_CUST_NUM");

if (str1 == null) {
throw new BneMissingParameterException("Customer Number Field Error");
}


try {
sagarSupplierSiteNameSQL =
new SagarSupplierSiteNameSQL(paramBneWebAppsContext,
bneSQLStatement1.getStatement());
BneSQLStatement bneSQLStatement2 =
new BneSQLStatement(sagarSupplierSiteNameSQL.getQuery(),
new Object[] { str1 });

bneSQLStatement2.append("", bneSQLStatement1.getBindValues());
bneResultSet =
sagarSupplierSiteNameSQL.getBneResultSet(bneSQLStatement2.getBindValuesAsArray());
} catch (Exception exception) {
throw new BneFatalException(exception.toString());
}


return bneResultSet;
}


}

终端:

-bash-3.00$ javac /apps/DEV/apps/apps_st/comn/java/classes   
/SagarSupplierSiteNameSQL.java -d "$JAVA_TOP/sager/sql"
-bash-3.00$
-bash-3.00$
-bash-3.00$
-bash-3.00$
-bash-3.00$ javac /apps/DEV/apps/apps_st/comn/java/classes
/SagarSupplierSiteNameValidator.java -d "$JAVA_TOP/sager/validator"
/apps/DEV/apps/apps_st/comn/java/classes
/SagarSupplierSiteNameValidator.java:15: package sagar.sql does not exist
import sagar.sql.SagarSupplierSiteNameSQL;
^
/apps/DEV/apps/apps_st/comn/java/classes
/SagarSupplierSiteNameValidator.java:27: cannot find symbol
symbol : class SagarSupplierSiteNameSQL
location: class sagar.validator.SagarSupplierSiteNameValidator
SagarSupplierSiteNameSQL sagarSupplierSiteNameSQL = null;
^
/apps/DEV/apps/apps_st/comn/java/classes
/SagarSupplierSiteNameValidator.java:45: cannot find symbol
symbol : class SagarSupplierSiteNameSQL
location: class sagar.validator.SagarSupplierSiteNameValidator
new SagarSupplierSiteNameSQL(paramBneWebAppsContext,
^
`3 errors

如果您需要有关我面临的问题的更多信息,请询问我并帮助我。

最佳答案

由于您使用交叉导入,因此文件不会单独编译。您必须立即编译所有文件。

此外,您的类不在 java 文件顶部所说的包内。从两个文件中删除 package sagar.validator;package sagar.sql; 并运行以下命令:

javac /apps/DEV/apps/apps_st/comn/java/*.java

如果你想使用包,请移动/apps/DEV/apps/apps_st/comn/java/sagar/sql 文件夹内的 SagarSupplierSiteNameSQL.java

SagarSupplierSiteNameValidator.java 位于 /apps/DEV/apps/apps_st/comn/java/sagar/validator 内。

进入 /apps/DEV/apps/apps_st/comn/java ,以下 2 个命令中的任何 1 个都应该有效。

javac  **/*.java 

javac  **/**/*.java

关于java - 如何创建 Java 包以及如何将它们导入到另一个包中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47960684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com