2017-08-29 7 views
1

(1)Esperデータベースアダプタをプロジェクトに接続する必要があります。イムガイドとしてthis を使用して、しかし、イムは、このエラーを取得しているので、私はどこの設定ファイルを見つけることが分からない:Cannot locate configuration information for database 'db1'EsperとPostgreSQLを接続

は、これは私が

public class Esper { 


public void iniciar() { 
    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(); 

    ConfigurationDBAdapter adapterConfig = new ConfigurationDBAdapter(); 
    ConfigurationDBRef configDB = new ConfigurationDBRef(); 
    configDB.setDriverManagerConnection("org.postgresql.Driver", 
      "jdbc:postgresql://localhost:5432/db_name", 
      "user", 
      "pass"); 
    adapterConfig.getJdbcConnections().put("db1", configDB); 

    EsperIODBAdapter dbAdapter = new EsperIODBAdapter(adapterConfig, "engineURI"); 
    dbAdapter.start(); 

    String expression = "select * from pattern[every timer :interval(10)], sql:db1 ['select mosquitoId from registros where velocidad > 50']"; 
    EPStatement stmt = epService.getEPAdministrator().createEPL(expression); 
    Mylistener listener = new Mylistener(); 
    stmt.addListener(listener); 
} 
} 

持っているもの(2)私が行うために必要なものですテーブルRegistrosからデータを取得し、velocidad > 50がprintLn()を使用する場合、この例ではpatternとは分かりません。

+0

'sql:db1'の代わりに' sql:db_name'を使用する必要がありますか? –

+0

@YCF_L nop、私はすでに試しました –

答えて

0

"EPServiceProviderManager.getDefaultProvider();"の代わりに "あなたは "EPServiceProviderManager.getDefaultProvider(configuration);"を使いたいでしょう。

Configuration configuration = new Configuration(); 
ConfigurationDBRef configDB = new ConfigurationDBRef(); 
configDB.setDriverManagerConnection(....); 
configuration.addDatabaseReference("MyDB", configDB); 
EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration);