2023
Mastermind solution
07/08/23 09:59
Everybody knows the Mastermind game, here is a solution in SQL supporting 4 or 5 pawns with 4, 5, 6, 7, 8, … colors. You supply the problem definition as a JSON with the guesses you have attempted and their results: size is the number of pawns (4,5), ncolors the number of colors (4 to 8 usually), the guesses is an array of your attempts, the ids of the pawns and "p" (for placed correctly) and "n" for present but not placed correctly pawns. |
simple example to connect to ORACLE Cloud DB using the Wallet
28/04/23 13:50
package YOUR_PACKAGE;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import oracle.jdbc.OracleConnection;
import oracle.jdbc.pool.OracleDataSource;
public class TestDBConnect {
final static String DB_URL = "jdbc:oracle:thin:/@DB_NAME_high?TNS_ADMIN=/etc/oracle/wallet";
final static String DB_USER = "USERNAME";
final static String DB_PASSWORD = "PASSWORD";
public static void main(String args[]) throws SQLException {
Properties info = new Properties();
info.put(OracleConnection.CONNECTION_PROPERTY_USER_NAME, DB_USER);
info.put(OracleConnection.CONNECTION_PROPERTY_PASSWORD, DB_PASSWORD);
// set other properties at your taste
info.put(OracleConnection.CONNECTION_PROPERTY_DEFAULT_ROW_PREFETCH, "20");
info.put(OracleConnection.CONNECTION_PROPERTY_AUTOCOMMIT, Boolean.FALSE);
info.put(OracleConnection.CONNECTION_PROPERTY_FAN_ENABLED, Boolean.FALSE);
OracleDataSource ods = new OracleDataSource();
ods.setURL(DB_URL);
ods.setConnectionProperties(info);
try (OracleConnection connection = (OracleConnection) ods.getConnection()) {
try (Statement statement = connection.createStatement()) {
try (ResultSet resultSet = statement.executeQuery("YOUR QUERY")) {
while (resultSet.next()) {
...
}
}
}
}
}
}
The Maven pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0
<groupId>YOUR_GROUP
<artifactId>YOUR_ARTIFACT
<version>0.0.1-SNAPSHOT
<name>Test JDBC Wallet
<properties>
<project.build.sourceEncoding>UTF-8
<project.reporting.outputEncoding>UTF-8
<jdk.version>11
<java.version>11
<ojdbc8.version>21.9.0.0
<maven.compiler.source>11
<maven.compiler.target>11
</properties>
<dependencies>
<dependency>
<groupId>com.oracle.database.jdbc
<artifactId>ojdbc8
<version>${ojdbc8.version}
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc
<artifactId>ucp
<version>${ojdbc8.version}
</dependency>
<dependency>
<groupId>com.oracle.database.security
<artifactId>oraclepki
<version>${ojdbc8.version}
</dependency>
<dependency>
<groupId>com.oracle.database.xml
<artifactId>xdb
<version>${ojdbc8.version}
</dependency>
<dependency>
<groupId>com.oracle.database.xml
<artifactId>xmlparserv2
<version>${ojdbc8.version}
</dependency>
<dependency>
<groupId>com.oracle.database.security
<artifactId>osdt_core
<version>${ojdbc8.version}
</dependency>
<dependency>
<groupId>com.oracle.database.security
<artifactId>osdt_cert
<version>${ojdbc8.version}
</dependency>
</dependencies>
</project>