Archived
Private
Public Access
1
0

Initial commit

This commit is contained in:
2022-09-04 12:45:01 +02:00
commit f4a01d6a69
11601 changed files with 4206660 additions and 0 deletions

3
Java/RandomGenerator/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@@ -0,0 +1,9 @@
<component name="ArtifactManager">
<artifact type="jar" name="RandomGenerator:jar">
<output-path>$PROJECT_DIR$/out/artifacts/RandomGenerator_jar</output-path>
<root id="archive" name="RandomGenerator.jar">
<element id="module-output" name="RandomGenerator" />
<element id="extracted-dir" path="$PROJECT_DIR$/../MySQL Connector.jar" path-in-jar="/" />
</root>
</artifact>
</component>

View File

@@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="MySQL Connector">
<CLASSES>
<root url="jar://$PROJECT_DIR$/../MySQL Connector.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

6
Java/RandomGenerator/.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
Java/RandomGenerator/.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/RandomGenerator.iml" filepath="$PROJECT_DIR$/RandomGenerator.iml" />
</modules>
</component>
</project>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="MySQL Connector" level="project" />
</component>
</module>

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: de.craftix.generator.Generator

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: de.craftix.generator.Generator

View File

@@ -0,0 +1,40 @@
package de.craftix.generator;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;
public class Generator {
public static MySQL sql;
public static int id = 0;
public static void main(String[] args) {
//TODO: Add MySQL Connection
sql = new MySQL("server.craftgang.de", 3306, "randomiser", "randomiser", "Kz.iJfkEmi.EBu2O");
sql.connect();
sql.insert("CREATE TABLE IF NOT EXISTS Results (ID INT(10), Timestamp VARCHAR(50), Number VARCHAR(100), Trys BIGINT(255))");
startRandomLoop();
}
private static void startRandomLoop() {
long trys = 0;
Random rand = new Random();
while (!Thread.currentThread().isInterrupted()) {
float value = rand.nextFloat();
System.out.print(value + "; ");
if (value > 0.9999999f) {
success(trys, value);
trys = 0;
id++;
}
trys++;
}
}
private static void success(long trys, float number) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
sql.insert("INSERT INTO Results (ID, Timestamp, Trys, Number) VALUES (" + id + ", \"" + dtf.format(now) + "\", " + trys + ", \"" + number + "\")");
}
}

View File

@@ -0,0 +1,62 @@
package de.craftix.generator;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
public class MySQL implements Serializable {
protected String server;
protected int port;
protected String database;
protected String username;
protected String password;
protected Connection con;
public MySQL(String server, int port, String database, String username, String password) {
this.server = server;
this.port = port;
this.database = database;
this.username = username;
this.password = password;
}
public MySQL(String server, String database, String username, String password) { this(server, 3306, database, username, password); }
public void connect() {
if (isConnected()) return;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://" + server + ":" + port + "/" + database, username, password);
}catch (Exception e) {
e.printStackTrace();
}
}
public void disconnect() {
if (!isConnected()) return;
try {
con.close();
con = null;
}catch (Exception e) { e.printStackTrace(); }
}
public boolean isConnected() { return con != null; }
public void insert(String qry) {
if (!isConnected()) throw new NullPointerException("MySQL not connected");
try {
con.prepareStatement(qry).executeUpdate();
}catch (Exception e) { e.printStackTrace(); }
}
public ResultSet getData(String qry) {
if (!isConnected()) throw new NullPointerException("MySQL not connected");
try {
return con.prepareStatement(qry).executeQuery();
}catch (Exception e) { e.printStackTrace(); }
return null;
}
}