crwdns132193:0crwdne132193:0

crwdns132195:0crwdne132195:0

crwdns132197:0crwdne132197:0

crwdns132199:0crwdne132199:0

  • crwdns132201:0crwdne132201:0

  • crwdns132203:0crwdne132203:0

  • crwdns132205:0crwdne132205:0

Warning

crwdns132207:0crwdne132207:0

crwdns132209:0crwdne132209:0

crwdns132211:0crwdne132211: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();
    }

}

crwdns132213:0crwdne132213:0

crwdns132215:0crwdne132215:0

crwdns132217:0crwdne132217:0