DB connection for DDL in groovy

DANGER!!!

In hybris hac, you cannot run DDL (data definition language) commands. You need unprotected connection to db. You can use below groovy example. Attention: DDL commands are dangerous!!!

import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

def config = spring.getBean("configurationService").getConfiguration();

DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(config.getString("db.driver"));
dataSource.setUrl(config.getString("db.url"));
dataSource.setUsername(config.getString("db.username"));
dataSource.setPassword(config.getString("db.password"));
JdbcTemplate jdbc = new JdbcTemplate(dataSource)
jdbc.execute("ALTER TABLE MYTABLE ALTER (P_MYFIELD BIGINT)");

Getting external IP with groovy

URL url = new URL("http://mkysoft.com/ip.php");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStream is = connection.getInputStream();
return org.apache.commons.io.IOUtils.toString(is);