Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package database;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.util.ArrayList;
- public class main {
- public static void main(String [] args) throws Exception {
- // createTable();
- // einsetzen();
- get();
- }
- public static void get() throws Exception {
- try {
- Connection con = getConnection();
- PreparedStatement statement = con.prepareStatement("SELECT Funktion, Wert FROM config");
- ResultSet result = statement.executeQuery();
- FileWriter writer;
- File datei = new File("test.cfg");
- writer = new FileWriter(datei);
- while(result.next()) {
- writer.write(result.getString("Funktion"));
- writer.write(" ");
- writer.write(result.getString("Wert"));
- writer.write(System.getProperty("line.separator"));
- }
- writer.flush();
- }catch(Exception e) {
- System.out.println(e);
- }
- }
- // public static void einsetzen() throws Exception {
- //
- // try {
- // Connection con = getConnection();
- //
- //
- // PreparedStatement einsetzen = con.prepareStatement("INSERT INTO config (Funktion, Wert) VALUES ('aimbot_active','1') ");
- // einsetzen.executeUpdate();
- // }catch(Exception e) {
- // System.out.println(e);
- // }
- // finally {
- // System.out.println("Default Werte eingesetzt");
- // }
- // }
- // public static void createTable() throws Exception {
- // try {
- // Connection con = getConnection();
- //
- // PreparedStatement create = con.prepareStatement("CREATE TABLE IF NOT EXISTS config(Funktion VARCHAR(100),Wert INT(100), PRIMARY KEY(Funktion))");
- // create.executeUpdate();
- //
- // }catch(Exception e) {
- // System.out.println(e);
- // }
- // finally {
- // System.out.println("Function executed");
- // }
- // }
- public static Connection getConnection() throws Exception{
- try {
- String host = "sql8.freesqldatabase.com";
- String port = "3306";
- String database = "sql8188659";
- String username = "sql8188659";
- String password = "9BsTH3YGPy";
- String driver = "com.mysql.jdbc.Driver";
- String url = "jdbc:mysql://"+ host +":"+ port +"/"+ database ;
- Class.forName(driver);
- Connection conn = DriverManager.getConnection(url, username, password);
- System.out.println("Connected");
- return conn;
- } catch(Exception e) {
- System.out.println(e);
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement