crwdns33303:0crwdne33303:0

crwdns33306:0crwdne33306:0

crwdns33307:0crwdne33307:0

crwdns33308:0crwdne33308:0

  • crwdns33309:0crwdne33309:0

  • crwdns33310:0crwdne33310:0

  • crwdns33311:0crwdne33311:0

Warning

crwdns33313:0crwdne33313:0

crwdns33314:0crwdne33314:0

crwdns33315:0crwdne33315:0

import org.spongepowered.api.Sponge;
import org.spongepowered.api.service.sql.SqlService;

import java.sql.Connection;
import java.sql.SQLException;

private SqlService sql;
public javax.sql.DataSource getDataSource(String jdbcUrl) throws SQLException {
    if (sql == null) {
        sql = Sponge.getServiceManager().provide(SqlService.class).get();
    }
    return sql.getDataSource(jdbcUrl);
}

// Later on
public void myMethodThatQueries() throws SQLException {
    Connection conn = getDataSource("jdbc:h2:imalittledatabaseshortandstout.db").getConnection();
    try {
        conn.prepareStatement("SELECT * FROM test_tbl").execute();
    } finally {
        conn.close();
    }

}

crwdns33316:0crwdne33316:0

crwdns33317:0crwdne33317:0

crwdns33318:0crwdne33318:0