小编zig*_*ggy的帖子

Maven - 从外部属性文件中读取属性

我有一个属性文件,包含以下内容

junit.version=3.8.1
dbcp.version=5.5.27
oracle.jdbc.version=10.2.0.2.0
Run Code Online (Sandbox Code Playgroud)

我尝试从我的pom文件中读取这些属性,如下所示

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>${junit.version}</version>
  <scope>test</scope>
</dependency>


<dependency>
    <groupId>dbcp</groupId>
    <artifactId>dbcp</artifactId>
    <version>${dbcp.version}</version>
    <scope>provided</scope>
</dependency>
<dependency>
  <groupId>com.oracle</groupId>
  <artifactId>ojdbc14</artifactId>
  <version>${oracle.jdbc.version}</version>
  <scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

和插件配置

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <executions>
           <!-- Associate the read-project-properties goal with the initialize phase, to read the properties file. -->
          <execution>
            <phase>initialize</phase>
            <goals>
              <goal>read-project-properties</goal>
            </goals>
            <configuration>
              <files>
                <file>../live.properties</file>
              </files>
            </configuration>
          </execution>
        </executions>
      </plugin>
Run Code Online (Sandbox Code Playgroud)

我发现当我运行mvn clean install时它找不到属性,而是出现以下错误:

'dependencies.dependency.version' for junit:junit:jar must be a valid version but is '${junit.version}'. @ line 23, column 16
'dependencies.dependency.version' for dbcp:dbcp:jar must be …
Run Code Online (Sandbox Code Playgroud)

build release-management maven

17
推荐指数
1
解决办法
2万
查看次数

XML命名空间如何工作

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"

       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.1.xsd">

  <context:component-scan
      base-package="com.springinaction.chapter01.knight" />

</beans>
Run Code Online (Sandbox Code Playgroud)

上面的示例显示了具有多个名称空间的XML文件的示例.这些命名空间的目的是什么,最重要的是,即使没有Internet连接,它们也能正常工作?

我认为第二位开头xsi:schemaLocation包含XML模式文件,用于验证XML文档的结构.如果我在不在网络上的计算机上运行使用此配置文件的应用程序,为什么这些仍然有效?URL是否以某种方式别名为JAR文件?

java xml spring xsd xml-namespaces

16
推荐指数
2
解决办法
4830
查看次数

MySQL相当于Oracle的SEQUENCE.NEXTVAL

我需要能够生成运行查询,该查询将返回下表中的下一个ID值:

CREATE TABLE animals (
     id MEDIUMINT NOT NULL AUTO_INCREMENT,
     name CHAR(30) NOT NULL,
     PRIMARY KEY (id)
)
Run Code Online (Sandbox Code Playgroud)

在Oracle中,您可以在序列上调用NEXTVAL,它会为您提供下一个序列(注意:无需在表上插入).

谷歌搜索后,我发现你可以使用以下查询找到auto_increment的当前值:

SELECT Auto_increment 
FROM information_schema.tables 
WHERE table_name='animals';
Run Code Online (Sandbox Code Playgroud)

问题是我希望每次查询值时增加值.在Oracle中,当您调用nextval时,即使您没有在表中插入行,序列的值也会增加.

有什么方法可以修改上面的查询,以便返回的值总是与上次调用查询时不同?即每次检查时Auto_increment都会递增,当在查询中使用时,它将使用新值.

我正在使用Spring JDBCTemplate,所以如果可以在一个查询中完成,那就更好了.

mysql sql database oracle spring

14
推荐指数
3
解决办法
8万
查看次数

Java修饰符的语法和格式

我发现自己对访问顺序和非访问修饰符感到困惑.例如

abstract void go()  
abstract public void go()  
public final void go()  
void final go()  

final class Test{}  
class final Test{}  
final abstract class Test{}  
abstract final Test{}  
Run Code Online (Sandbox Code Playgroud)

我永远不知道正确的顺序是什么,有时候我弄错了,因为有太多可能的组合.对于哪一个应该先于另一个有明确的指导?

是否有任何关于它们在代码中出现的格式和顺序的描述?我想提出一个语法指南,但我不确定它是否100%正确.这里是:

Methods:  
[access modifier | nonaccess modifier] return-type method-name  

Classes:  
[access modifier | nonaccess modifier] class class-name  

Interfaces:  
[access modifier | nonaccess modifier] interface interface-name       

Variables:  
[access modifier | nonaccess modifier] variable-type variale-name  
Run Code Online (Sandbox Code Playgroud)

java syntax coding-style

12
推荐指数
2
解决办法
5597
查看次数

使用带有布尔IN参数的CallableStatement在Java中调用Oracle PL/SQL过程会产生PLS-00306 oracle错误:

我在Oracle 11g上有一个pl/sql过程,它具有以下参数:

PROCEDURE validate_product
   ( product_id_in IN varchar2 , 
     username_in in varchar2, 
     source_in varchar2,    
     source_id_in varchar2 , 
     isEuProduct in boolean , 
     error_code out varchar2, 
     product_type out varchar2  
     )
Run Code Online (Sandbox Code Playgroud)

我试图使用以下代码从java中调用上面的存储过程:

cstmt = getConnection().prepareCall("begin " + DBUtil.SCHEMANAME + ".PRODUCT_UTILITIES.validate_product(:1,:2,:3,:4,:5,:6,:7); end;");

cstmt.registerOutParameter(6, Types.CHAR); 
cstmt.registerOutParameter(7, Types.CHAR); 

cstmt.setString(1, productId);
cstmt.setString(2, username);
cstmt.setString(3, sourceName);
cstmt.setString(4, sourceId);
cstmt.setBoolean(5, isEUProduct);

cstmt.execute();
Run Code Online (Sandbox Code Playgroud)

该类型的Java变量都String以异常的isEUProductboolean.每当我运行上述程序时,我都会收到以下错误:

PLS-00306: wrong number or types of arguments in call to validate_product ORA-06550: line 1, column 7: PL/SQL: Statement ignored"
Run Code Online (Sandbox Code Playgroud)

我必须调试程序一百次,但一切似乎都是正确的类型,参数的数量是正确的. …

java sql oracle plsql jdbc

12
推荐指数
3
解决办法
2万
查看次数

无法向基于Spring MVC的REST服务发送多部分/混合请求

我有一个基于Spring MVC和Resteasy的REST服务,我需要通过发送multipart/mixed请求进行测试.

该服务编码如下:

@POST
    @Path("/mixedMimeText")
    @Consumes("multipart/mixed")
    @ResponseStatus(HttpStatus.OK)
    public String createMime(@Context ServletContext servletContext, MultipartInput input) throws Exception, IOException {

        logger.info("Processing /mixedMimeText");

        for(InputPart p : input.getParts()){
            logger.info("Headers : " + p.getHeaders());
            logger.info("MediaType : " + p.getMediaType());
            logger.info("Body : " +  p.getBodyAsString());
            logger.info("--------------------------------------------------- ");
        }

        return "TEST";
    }
Run Code Online (Sandbox Code Playgroud)

我使用以下文件作为multipart mime内容发送

--ABC123Boundary
Content-Type: text/xml

<?xml version="1.0" ?>
<request>
<account-id>XXXX-XXXX-XXXX-XXXX</account-id>
<reference>12345</reference>
<app-name>XXXXXXXXX</app-name>
<information>
<calling-party>
<name>Joe Bloggs</name>
<identifier>441234567890</identifier>
</calling-party>
<called-party>
<name>John Smith</name>
<identifier>15551234567</identifier>
</called-party>
</information>
</request>

--ABC123Boundary
Content-Type: text/xml

UklGRkBAAABXQVZFZm10IBAAAAAHAAEAQB8AAEAfAAABAAgAZmFjdAQAAAAPQ
AAAZGF0YRBAAABn5///////////////5///Z+fn///n////////5////////2f//2f//+f//+f////n/
///////52f//////2f//////2f/////5////////+f/////Z+f///////////////9n//9nZ/9n////5+f///9
<snip>
//+f//////2f/////////5//n//////////9n

--ABC123Boundary--
Run Code Online (Sandbox Code Playgroud)

我使用curl客户端使用以下命令发送请求: …

java spring curl spring-mvc

11
推荐指数
1
解决办法
3万
查看次数

Listagg函数和ORA-01489:字符串连接的结果太长

当我运行以下查询时:

 Select
  tm.product_id,
  listagg(tm.book_id || '(' || tm.score || ')',',')
    within group (order by tm.product_id) as matches
from
  tl_product_match tm 
where
  tm.book_id is not null 
group by
  tm.product_id
Run Code Online (Sandbox Code Playgroud)

Oracle返回以下错误:

 ORA-01489: result of string concatenation is too long
Run Code Online (Sandbox Code Playgroud)

我知道失败的原因是listagg函数试图连接大于4000个字符的值,这些值不受支持.

我已经看到了这里描述的替代示例 - http://www.oracle-base.com/articles/misc/string-aggregation-techniques.php但它们都需要使用函数或过程.

是否有一个纯SQL的解决方案,而无需调用函数或存储过程,并且能够使用标准JDBC读取值?

我遇到的另一个困难是我见过的大多数字符串聚合示例都显示了如何按原样读取值的示例.在我的例子中,我首先修改了值(即我正在聚合两列).

java oracle jdbc oracle10g oracle11g

11
推荐指数
2
解决办法
2万
查看次数

枚举实例默认是静态的吗?

enum Animals{
    DOG("woof"),
    CAT("Meow"),
    FISH("Burble");

    String sound;

    Animals(String s) {
            sound = s;
    }
}
public class TestEnum{
    static Animals a;
    public static void main(String ab[]){
        System.out.println( a );
        System.out.println( a.DOG.sound + " " + a.FISH.sound);
    }
}
Run Code Online (Sandbox Code Playgroud)

在上面的例子中,为什么我们能够访问枚举的实例(即作为a.DOG.sound)当a为null并且枚举未声明为静态时?枚举实例默认是静态的吗?

java enums

10
推荐指数
2
解决办法
5988
查看次数

隐藏的字段虽然继承

在以下代码示例中:

class Parent { 
    int x =5;
    public Integer aMethod(){

        System.out.print("Parent.aMthod ");
        return x;
    }
}

class Child extends Parent {
    int x =6;
    public Integer aMethod(){
        System.out.print("Child.aMthod "); 
        return x;
    }
}


class ZiggyTest2{

    public static void main(String[] args){

        Parent p = new Child();
        Child c = new Child();

        System.out.println(p.x + " " + c.x);

        System.out.println(p.aMethod() + "  \n");
        System.out.println(c.aMethod() + "  \n");
    }   
}
Run Code Online (Sandbox Code Playgroud)

并输出:

5 6
Child.aMthod 6  

Child.aMthod 6
Run Code Online (Sandbox Code Playgroud)

p.aMethod()当px打印6时,为什么不打印6?

谢谢

编辑

哎呀一个小错字:问题应该是"为什么p.aMethod()在px print 5时不打印5" …

java oop inheritance scjp

10
推荐指数
1
解决办法
1110
查看次数

如何向XML DOM对象添加名称空间前缀?

我正在尝试使用特定的命名空间构建XML文档.我想要生成的最终文档看起来像这样:

<m:documentObject xmlns:m="http://www.myschema.com">
    <sender>token</sender>
    <receiver>token</receiver>
    <payload>token</payload>
</m:documentObject>
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止所拥有的.

Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element requestElement = document.createElementNS("http://www.myschema.com", "documentObject");

document.appendChild(requestElement);

Element sender = document.createElement("sender");
requestElement.appendChild(sender);     
Text senderText = document.createTextNode("Xmlsender");
sender.appendChild(senderText); 

Element receiver = document.createElement("receiver");
requestElement.appendChild(receiver);       
Text receiverText = document.createTextNode("Xmlreceiver");
receiver.appendChild(receiverText); 

Element payload = document.createElement("payload");
requestElement.appendChild(payload);        
Text payloadText = document.createTextNode("Xmlpayload");
payload.appendChild(payloadText);   

StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);

DOMSource source = new DOMSource(requestElement);

TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); 
transformer.transform(source, result);

String xmlString = sw.toString();
System.out.println(xmlString) …
Run Code Online (Sandbox Code Playgroud)

java xml spring dom jaxb

10
推荐指数
1
解决办法
2万
查看次数