Advertisement
Guest User

Untitled

a guest
Aug 4th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. package database;
  2.  
  3. import java.io.File;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6. import java.sql.Connection;
  7. import java.sql.DriverManager;
  8. import java.sql.PreparedStatement;
  9. import java.sql.ResultSet;
  10. import java.util.ArrayList;
  11.  
  12. public class main {
  13.  
  14.  
  15. public static void main(String [] args) throws Exception {
  16.  
  17. // createTable();
  18. // einsetzen();
  19. get();
  20. }
  21. public static void get() throws Exception {
  22. try {
  23. Connection con = getConnection();
  24.  
  25.  
  26. PreparedStatement statement = con.prepareStatement("SELECT Funktion, Wert FROM config");
  27.  
  28. ResultSet result = statement.executeQuery();
  29.  
  30.  
  31.  
  32. FileWriter writer;
  33. File datei = new File("test.cfg");
  34. writer = new FileWriter(datei);
  35.  
  36.  
  37. while(result.next()) {
  38.  
  39.  
  40. writer.write(result.getString("Funktion"));
  41. writer.write(" ");
  42. writer.write(result.getString("Wert"));
  43. writer.write(System.getProperty("line.separator"));
  44.  
  45.  
  46.  
  47.  
  48. }
  49.  
  50. writer.flush();
  51.  
  52. }catch(Exception e) {
  53. System.out.println(e);
  54. }
  55.  
  56. }
  57. // public static void einsetzen() throws Exception {
  58. //
  59. // try {
  60. // Connection con = getConnection();
  61. //
  62. //
  63. // PreparedStatement einsetzen = con.prepareStatement("INSERT INTO config (Funktion, Wert) VALUES ('aimbot_active','1') ");
  64. // einsetzen.executeUpdate();
  65. // }catch(Exception e) {
  66. // System.out.println(e);
  67. // }
  68. // finally {
  69. // System.out.println("Default Werte eingesetzt");
  70. // }
  71. // }
  72. // public static void createTable() throws Exception {
  73. // try {
  74. // Connection con = getConnection();
  75. //
  76. // PreparedStatement create = con.prepareStatement("CREATE TABLE IF NOT EXISTS config(Funktion VARCHAR(100),Wert INT(100), PRIMARY KEY(Funktion))");
  77. // create.executeUpdate();
  78. //
  79. // }catch(Exception e) {
  80. // System.out.println(e);
  81. // }
  82. // finally {
  83. // System.out.println("Function executed");
  84. // }
  85. // }
  86. public static Connection getConnection() throws Exception{
  87.  
  88. try {
  89. String host = "sql8.freesqldatabase.com";
  90. String port = "3306";
  91. String database = "sql8188659";
  92. String username = "sql8188659";
  93. String password = "9BsTH3YGPy";
  94.  
  95.  
  96. String driver = "com.mysql.jdbc.Driver";
  97. String url = "jdbc:mysql://"+ host +":"+ port +"/"+ database ;
  98.  
  99. Class.forName(driver);
  100.  
  101. Connection conn = DriverManager.getConnection(url, username, password);
  102.  
  103. System.out.println("Connected");
  104.  
  105. return conn;
  106.  
  107. } catch(Exception e) {
  108. System.out.println(e);
  109. }
  110.  
  111. return null;
  112.  
  113. }
  114.  
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement