M
M
Mark Ivanych2017-08-28 21:02:07
Java
Mark Ivanych, 2017-08-28 21:02:07

Spring and SphinxSearch how to use?

Hello, I do not understand how to use it correctly.
Works,

@Bean
    public Connection sqlSphinx() throws SQLException, ClassNotFoundException {
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection(sphinxUrl, "", "");
        return conn;
    }

It turns out that one connection is created for all? If you close it at the end, then the next connection will be an exception.
After some time, this connection is also closed for some reason.
Do I need to use some kind of pool?
Absolutely did not find infa on a spring and a sphinx.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mark Ivanych, 2017-08-30
@iormark

In general, I was confused by Hikari, Shinx does not work with him.
But commons-dbcp2 works fine)

@Bean
    public DataSource sphinxDataSource() {
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUsername("");
        dataSource.setPassword("");
        dataSource.setUrl(sphinxUrl);
        return dataSource;
    }

    @Bean
    public JdbcTemplate sphinxJdbcTemplate() throws SQLException, ClassNotFoundException {
        return new JdbcTemplate(sphinxDataSource());
    }

    @Bean
    public Connection sphinxJdbc() throws SQLException, ClassNotFoundException {
        return sphinxDataSource().getConnection();
    }

P
Puma Thailand, 2017-08-29
@opium

you are using a regular muscle driver,
respectively, read the spring muscle docks,
it seems to me that you can already raise the pool in it by default

P
protven, 2017-08-29
@protven

Lord, what a horror. class.forName, DriverManager... As if plunged into the 90s. Take a normal pool of connections and don't worry. c3po, HikariCP, tomcat jdbc pool etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question