servicemix中blueprint.xml中的sql数据源

servicemix中blueprint.xml中的sql数据源,sql,datasource,apache-servicemix,Sql,Datasource,Apache Servicemix,}您必须在camel/spring上下文中将数据源bean注入数据库beanh2中,如下所示: private DataSource dataSource; private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseBeanH2.class); public DatabaseBeanH2(){} public void setDataSource(DataSource dataSource) { this

}

您必须在camel/spring上下文中将数据源bean注入数据库beanh2中,如下所示:

private DataSource dataSource;
private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseBeanH2.class);

public DatabaseBeanH2(){}

public void setDataSource(DataSource dataSource) {
    this.dataSource = dataSource;
}

public void create() throws SQLException{
    Statement sta = dataSource.getConnection().createStatement();
    try {
        sta.executeUpdate("CREATE TABLE orders ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, item VARCHAR(50), amount INT, description VARCHAR(300), processed BOOLEAN, consumed BOOLEAN);");
    } catch (SQLException e) {
        LOGGER.info("Table orders already exists");
    }
}

public void destroy() throws SQLException {
    dataSource.getConnection().close();
}

请在尝试连接的位置共享代码。无法使用上述信息进行分析。如果您的数据源配置正确,您还可以使用servicemix/karaf shell中的jdbc:commands进行检查。@Vrushali Shinde此问题/答案与的重复,请停留在一个主题上,社区不必也不接受多次提出相同的问题。
private DataSource dataSource;
private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseBeanH2.class);

public DatabaseBeanH2(){}

public void setDataSource(DataSource dataSource) {
    this.dataSource = dataSource;
}

public void create() throws SQLException{
    Statement sta = dataSource.getConnection().createStatement();
    try {
        sta.executeUpdate("CREATE TABLE orders ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, item VARCHAR(50), amount INT, description VARCHAR(300), processed BOOLEAN, consumed BOOLEAN);");
    } catch (SQLException e) {
        LOGGER.info("Table orders already exists");
    }
}

public void destroy() throws SQLException {
    dataSource.getConnection().close();
}
<bean id="databaseBean" class="my.package.DatabaseBeanH2">
    <property name="dataSource" ref="dataSource" />
</bean>