2016-09-23 12 views
-1

私は春のアプリケーションに取り組んでいます。データを取得しようとすると、SQLExceptionが発生する

Error org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [SELECT dstoreNumber, details, VALUE FROM dstore.table1 where value='400s' ]; nested exception is java.sql.SQLException: ORA-00942: table or view does not exist 

私は2台の異なるデータベース・サーバに配置されている2つの異なるスキーマに接続しています:私はrecords.Belowは例外で取得するには、データベースとの接続に問題に直面しています。

私は1つのクラスに2つのJdbcTemplateオブジェクトを作成しました。以下は私のコードです。

spring-beans.properties

##### dstore Datasource ##### 
dstore.dataSource.url=jdbc:oracle:thin:@dstore1.dev.xyz.com:5150:dstore 
dstore.dataSource.username=dstore 
dstore.dataSource.password=password 

##### dscon Datasource ##### 
dscon.dataSource.url=jdbc:oracle:thin:@dscon.dev.xyz.com:5150:dscon 
dscon.dataSource.username=dscon 
dscon.dataSource.password=password 

のsrc /メイン/リソース/ META-INF /データソース-config.xmlの

<bean name="dstoreDataSource" class="oracle.jdbc.pool.OracleConnectionPoolDataSource"> 
     <property name="URL" value="${dstore.dataSource.url}" /> 
     <property name="user" value="${dstore.dataSource.username}" /> 
     <property name="password" value="${dstore.dataSource.password}" /> 
    </bean> 
<bean name="dsconDataSource" class="oracle.jdbc.pool.OracleConnectionPoolDataSource"> 
     <property name="URL" value="${dscon.dataSource.url}" /> 
     <property name="user" value="${dscon.dataSource.username}" /> 
     <property name="password" value="${dscon.dataSource.password}" /> 
    </bean> 

のsrc /メイン/リソース/ META-INF/spring-

<import resource="classpath:META-INF/dstore/dstore-config.xml" /> 
<import resource="classpath:META-INF/dscon/dscon-config.xml" /> 
<bean name="jdbcTemplateServicedstore" class="org.springframework.jdbc.core.JdbcTemplate"> 
    <property name="dataSource" ref="dstoreDataSource" /> 
</bean> 
<bean name="jdbcTemplateServicedscon" class="org.springframework.jdbc.core.JdbcTemplate"> 
    <property name="dataSource" ref="dsconDataSource" /> 
</bean> 

のsrc /メイン/リソース/ META-INF/dstore/dstore-config.xmlにbeans.xmlの

<?xml version="1.0"?> 

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 

    <tx:annotation-driven proxy-target-class="false" /> 

    <bean id="dstoreServicingTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
     <property name="entityManagerFactory" ref="dstoreServicing" /> 
     <qualifier value="servicing" /> 
    </bean> 

    <bean id="dstoreServicing" 
     class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
     <property name="dataSource" ref="dstoreDataSource" /> 
     <property name="persistenceUnitName" value="dstoreServicing" /> 
     <property name="persistenceXmlLocation" 
      value="classpath:META-INF/dstore/jpa-persistence.xml" /> 
     <property name="jpaVendorAdapter"> 
      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> 
       <property name="showSql" value="true" /> 
       <property name="databasePlatform" value="org.hibernate.dialect.Oracle9iDialect" /> 
      </bean> 
     </property> 
    </bean> 
</beans> 

のsrc /メイン/リソース/ META-INF/DSCON/DSCON-config.xmlの

<?xml version="1.0"?> 

<beans 
    xmlns="http://www.springframework.org/schema/beans" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jee="http://www.springframework.org/schema/jee" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
     http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 

    <aop:aspectj-autoproxy proxy-target-class="false" /> 

    <context:annotation-config /> 

    <tx:annotation-driven transaction-manager="dsconTransactionManager" proxy-target-class="false" /> 

    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/> 

    <bean id="dsconTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
     <property name="dataSource" ref="dscondatasource" /> 
     <property name="entityManagerFactory" ref="dscon"/> 
    </bean> 

    <bean id="dscon" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
     <property name="dataSource" ref="dscondatasource" /> 
     <property name="persistenceUnitName" value="dscon" /> 
     <property name="persistenceXmlLocation" value="classpath:META-INF/myloans/jpa-persistence.xml" /> 
     <property name="jpaVendorAdapter"> 
      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> 
       <property name="showSql" value="true" /> 
       <property name="databasePlatform" value="org.hibernate.dialect.Oracle9iDialect" /> 
      </bean> 
     </property> 
     <property name="loadTimeWeaver"> 
      <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/> 
     </property> 
    </bean> 
</beans> 

Javaクラス:以下のクラスではmyDAO.getMethod2()が正常に実行されますが、私はmyDAOを呼び出していたときに.getMethod1()、例外 "テーブルまたはビューが存在しません"をスローします。

@component 
class LoadData{ 
    @Inject 
    private MyDAO myDAO; 

//Gets values from database 
    @PostConstruct 
    public void loadListCodes() 
    { 
    final List<MyDTO> listValues = myDAO.getMethod2(); //successfully connected to database 
     try { 
     final List<MyDTO> listValue = myDAO.getMethod1(); //unable to connect to Database, exception is thrown 
     LOG.info("Method1 : " + listValue); 
     } catch (Exception e) { 
      LOG.info("exception " + e); 
      System.out.println("exception is :: " + e); 
    } 
    //logic goes here 
    } 
    } 

Javaクラス:

@Repository 
public class MyDAOJDBCImpl implements MyDAO 
{ 

@Inject 
@Qualifier("jdbcTemplateServicedstore") 
private JdbcTemplate jdbcTemplate1; 

@Inject 
@Qualifier("jdbcTemplateServicedscon") 
private JdbcTemplate jdbcTemplate2; 

private static final String SQL1 = "SELECT dstoreNumber, details, VALUE FROM dstore.table1 " 
+ "WHERE value = '400S' "; 

private static final String SQL2 = "SELECT dsconNumber, details, VALUE FROM dscon.table1 " 
+ "WHERE value = '700S' "; 


public List<MyDTO> getMethod1() 
{ 
//unable to connect to database, throwing exception 
List<MyDTO> listValues = null; 
LOG.info("Retrieving data.."); 
try 
{ 
listValues = jdbcTemplate1.query(SQL1, 

new RowMapper<ListValueDTO>() 
{ 
public MyDTO mapRow(final ResultSet rs, final int rowNum) throws SQLException 
{ 
    final MyDTO listValueDTO = new MyDTO(); 
    listValueDTO.setdstoreNumber(rs.getString("dstoreNumber)); 
    listValueDTO.setDetails(rs.getString("details")); 
    listValueDTO.setValue(rs.getString("value")); 
    return listValueDTO; 
} 
}); 
} 
catch (Exception e) 
{ 
LOG.error("Error :" + e); 
} 

return listValues; 
} 

public List<MyDTO> getMethod2() 
{ 
List<MyDTO> listValues = null; 
LOG.info("Retrieving data.."); 
try 
{ 
    listValues = jdbcTemplate2.query(SQL2, 

    new RowMapper<ListValueDTO>() 
    { 
    public MyDTO mapRow(final ResultSet rs, final int rowNum) throws SQLException 
    { 
     final MyDTO listValueDTO = new MyDTO(); 
     //code goes here 
     return listValueDTO; 
    } 
    }); 
} 
catch (Exception e) 
{ 
    LOG.error("Error :" + e); 
} 

return listValues; 
} 
} 

PS:私は2台の異なるデータベース・サーバと異なるスキーマに配置されている2つの異なるテーブルに接続しています。私はgetMethod1()を呼び出してスキーマを見つけることができないか、他のデータベースサーバに接続できないと思います。どうすればこの問題を解決できますか?いずれか1つ前に直面した。私は、単一のJavaクラスの異なるサーバーに存在する別のデータベーステーブルを呼び出して実行する必要があります。

+0

TOADとAPPで同じOracleユーザーを使用していますか? – reos

+0

はい、データベースに接続するための資格情報を意味しますか?@reos – Ran

+0

はい、TOADでステートメントを実行できる場合、アプリケーションでステートメントを実行する可能性があります。おそらく、別のユーザーを使用しているか、別のステートメントを実行している可能性があります。 – reos

答えて

1

例外ORA-00942: table or view does not existは、通常、テーブルが存在しないことを示します。たとえば、テーブル名を間違えた場合や、このテーブルから選択する権限がない場合などです。

+0

私はテーブルがあり、私は助成金を持っています。私はTOADでクエリを実行し、結果を得ることができます。私は上記の私のコードで間違っているいくつかのマッピングを推測しています。 – Ran

関連する問題