---
title: "Kettle-JNDI模式-密码错误"
author: "flylynne"
date: "2021-02-05T22:12:19Z"
tags: []
categories: ["开源软件"]
slug: "kettle-jndi"
draft: false
lastmod: "2021-02-05T22:12:19Z"
id: 2519113
url: "https://flylynne.iteye.com/blog/2519113"
---

```
package org.osjava.sj.loader.util; 

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.InputStreamReader; 

public class CustomProperties extends AbstractProperties { 


    public synchronized void load(InputStream in) throws IOException { 
        try { 
            BufferedReader reader = new BufferedReader( new InputStreamReader(in) ); 
            String line = ""; 
            String nextLine = null; 
            while( (line = reader.readLine()) != null) { 


                // we may already be on a multi-line statement. 
                if(nextLine != null) { 
                    line = nextLine + line; 
                    nextLine = null; 
                } 


                line = line.trim(); 
                if(line.endsWith("\\")) { 
                    nextLine = line; 
                    continue; 
                } 


                int idx = line.indexOf('#'); 
                // remove comment 
                if(idx != -1) { 
                    line = line.substring(0,idx); 
                } 
                // split equals sign 
                idx = line.indexOf('='); 
                if(idx != -1) { 
                    this.setProperty(line.substring(0,idx), line.substring(idx+1)); 
                } else { 
                    // blank line, or just a bad line 
                    // we ignore it 
                } 
            } 
            reader.close(); 
        } catch(IOException ioe) { 
            ioe.printStackTrace(); 
        } 
    } 

} 
```

 

Kettle连接，使用OCI连接正常，但采用JNDI总是报账户密码不正确，原因是密码里面包含了#

我们通过配置 jdbc.properties 来使用 JNDI 模式连接数据库；  
这次我们的密码是OA\_R/password=A#123User

因为Kettle在解析 jdbc.properties 时，**如果遇到井号，会截取到井号前的内容该行后面的内容都将丢失、**

 

**源码**

[**https://github.com/pentaho/pentaho-simple-jndi/blob/master/src/main/java/org/osjava/sj/loader/util/CustomProperties.java?spm=a2c4e.10696291.0.0.285519a43Efnes&file=CustomProperties.java**](https://github.com/pentaho/pentaho-simple-jndi/blob/master/src/main/java/org/osjava/sj/loader/util/CustomProperties.java?spm=a2c4e.10696291.0.0.285519a43Efnes&file=CustomProperties.java)