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

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;
}
}