Last active
August 10, 2020 12:55
-
-
Save aalmiray/f8d5ef7baeb3b30b3102f13a032a37dc to your computer and use it in GitHub Desktop.
Groovy/JBang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab('com.oracle.database.jdbc:ojdbc8:19.7.0.0') | |
@Grab('com.oracle.database.jdbc:ucp:19.7.0.0') | |
import java.sql.Connection | |
import java.sql.SQLException | |
import java.sql.Statement | |
import java.sql.ResultSet | |
import oracle.ucp.jdbc.PoolDataSourceFactory | |
import oracle.ucp.jdbc.PoolDataSource | |
PoolDataSource pds = PoolDataSourceFactory.poolDataSource.with(true) { | |
connectionFactoryClassName = 'oracle.jdbc.pool.OracleDataSource' | |
setURL(System.properties['db.url']) | |
user = System.properties['db.username'] | |
password = System.properties['db.password'] | |
} | |
try (Connection conn = pds.connection) { | |
Statement stmt = conn.createStatement() | |
ResultSet rs = stmt.executeQuery('SELECT 1 FROM dual') | |
rs.next() | |
println(1 == rs.toRowResult()[0]? 'OK' : 'ERROR') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//usr/bin/env jbang "$0" "$@" ; exit $? | |
//DEPS com.oracle.database.jdbc:ojdbc8:19.7.0.0 | |
//DEPS com.oracle.database.jdbc:ucp:19.7.0.0 | |
import java.sql.Connection; | |
import java.sql.SQLException; | |
import java.sql.Statement; | |
import java.sql.ResultSet; | |
import oracle.ucp.jdbc.PoolDataSourceFactory; | |
import oracle.ucp.jdbc.PoolDataSource; | |
import java.math.BigDecimal; | |
public class db { | |
public static void main(String... args) throws Exception { | |
PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource(); | |
pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource"); | |
pds.setURL(System.getProperty("db.url")); | |
pds.setUser(System.getProperty("db.username")); | |
pds.setPassword(System.getProperty("db.password")); | |
try (Connection conn = pds.getConnection()) { | |
Statement stmt = conn.createStatement(); | |
ResultSet rs = stmt.executeQuery("SELECT 1 FROM dual"); | |
rs.next(); | |
if (BigDecimal.valueOf(1).equals(rs.getObject(1))) { | |
System.out.println("OK"); | |
} else { | |
System.out.println("ERROR"); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//usr/bin/env jbang "$0" "$@" ; exit $? | |
//DEPS com.oracle.database.jdbc:ojdbc8:19.7.0.0 | |
//DEPS com.oracle.database.jdbc:ucp:19.7.0.0 | |
import java.sql.Connection; | |
import java.sql.SQLException; | |
import java.sql.Statement; | |
import java.sql.ResultSet; | |
import oracle.ucp.jdbc.PoolDataSourceFactory; | |
import oracle.ucp.jdbc.PoolDataSource; | |
import java.math.BigDecimal; | |
PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource(); | |
pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource"); | |
pds.setURL(System.getProperty("db.url")); | |
pds.setUser(System.getProperty("db.username")); | |
pds.setPassword(System.getProperty("db.password")); | |
try (Connection conn = pds.getConnection()) { | |
Statement stmt = conn.createStatement(); | |
ResultSet rs = stmt.executeQuery("SELECT 1 FROM dual"); | |
rs.next(); | |
if (BigDecimal.valueOf(1).equals(rs.getObject(1))) { | |
System.out.println("OK"); | |
} else { | |
System.out.println("ERROR"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab("com.oracle.database.jdbc:ojdbc8:19.7.0.0") | |
@Grab("com.oracle.database.jdbc:ucp:19.7.0.0") | |
import java.sql.Connection; | |
import java.sql.SQLException; | |
import java.sql.Statement; | |
import java.sql.ResultSet; | |
import oracle.ucp.jdbc.PoolDataSourceFactory; | |
import oracle.ucp.jdbc.PoolDataSource; | |
@groovy.transform.CompileStatic | |
class db { | |
static void main(String... args) throws Exception { | |
PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource(); | |
pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource"); | |
pds.setURL(System.getProperty("db.url")); | |
pds.setUser(System.getProperty("db.username")); | |
pds.setPassword(System.getProperty("db.password")); | |
try (Connection conn = pds.getConnection()) { | |
Statement stmt = conn.createStatement(); | |
ResultSet rs = stmt.executeQuery("SELECT 1 FROM dual"); | |
rs.next(); | |
if (1 == rs.getObject(1)) { | |
System.out.println("OK"); | |
} else { | |
System.out.println("ERROR"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment