提取Oracle数据VARCHAR2(N BYTE)在JAVA中返回空白字符串

时间:2018-11-21 12:23:42

标签: java oracle fetch varchar2

我想知道什么时候发生了,我试图从ORACLE数据库中获取数据。列的数据类型为VARCHAR2(40 BYTE)NOT NULL ENABLE。

在@Thoma的评论部分中,我已将图片更改为文本。

在SQL DEVELOPPER中,我得到以下结果

Name:           app-raiden-migration-12-19-58-21-11-2018
Namespace:      localdev
Selector:       controller-uid=c2fd06be-ed87-11e8-8782-080027eeb8a0
Labels:         jobType=database-migration
Annotations:    kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"batch/v1","kind":"Job","metadata":{"annotations":{},"labels":{"jobType":"database-migration"},"name":"app-raiden-migration-12-19-58-21-1...
Parallelism:    1
Completions:    1
Start Time:     Wed, 21 Nov 2018 12:19:58 +0000
Pods Statuses:  0 Running / 0 Succeeded / 1 Failed
Pod Template:
  Labels:  controller-uid=c2fd06be-ed87-11e8-8782-080027eeb8a0
           job-name=app-raiden-migration-12-19-58-21-11-2018
  Containers:
   app:
    Image:  pp3-raiden-app:latest
    Port:   <none>
    Command:
      php
      artisan
      migrate
    Environment:
      DB_HOST:        local-mysql
      DB_PORT:        3306
      DB_DATABASE:    raiden
      DB_USERNAME:    <set to the key 'username' in secret 'cloudsql-db-credentials'>  Optional: false
      DB_PASSWORD:    <set to the key 'password' in secret 'cloudsql-db-credentials'>  Optional: false
      LOG_CHANNEL:    stderr
      APP_NAME:       Laravel
      APP_KEY:        ABCDEF123ERD456EABCDEF123ERD456E
      APP_URL:        http://192.168.99.100
      OAUTH_PRIVATE:  <set to the key 'oauth_private.key' in secret 'laravel-oauth'>  Optional: false
      OAUTH_PUBLIC:   <set to the key 'oauth_public.key' in secret 'laravel-oauth'>   Optional: false
    Mounts:           <none>
  Volumes:            <none>
Events:
  Type     Reason                Age   From            Message
  ----     ------                ----  ----            -------
  Normal   SuccessfulCreate      2m    job-controller  Created pod: app-raiden-migration-12-19-58-21-11-2018-pwnjn
  Warning  BackoffLimitExceeded  2m    job-controller  Job has reach the specified backoff limit

当我尝试以JAVA代码获取这些数据时:

SELECT ZONE_DESC FROM IC_RATE_ZONES;
"ZONE_DESC"
VIRGIN ISLANDS UK
VIRGIN ISLANDS US
WALLIS AND FUTUNA IS
YEMEN
ZAMBIA
ZAMBIA MOBILE

我在控制台输出中得到空白结果。

1 个答案:

答案 0 :(得分:0)

感谢大家花很多时间来回答它。 @secretsuperstar在评论部分提到了该解决方案,但我第一次做错了。

https://bjurr.com/jdbc-problem-resultset-getstring-returns-nothing/

它必须首先获取ASCII并读取它。数据类型使它变得复杂。

这是最终结果:

try{
        con = conn.getOracle();
        stm = con.createStatement();
         Rs = stm.executeQuery("select ZONE_DESC FROM IC_RATE_ZONES");

        while(Rs.next()){
            String str = new String();
            InputStreamReader in = new InputStreamReader(Rs.getAsciiStream("ZONE_DESC"));
            while(in.ready()){
                str = str + (char)in.read();
            }
            System.out.println(str);
        }
    } catch(Exception e){
        e.printStackTrace();
    }

谢谢大家。希望可以帮助别人