Guest User

Untitled

a guest
Mar 13th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.sql.Statement;
  10. import java.awt.*;
  11. import java.applet.*;
  12. import java.awt.event.*;
  13.  
  14. /** guide for event buttons...
  15. public boolean action(Event e, Object o) ..
  16. and listbox */
  17. // ... extends Applet, for handle button events
  18. public class first extends Applet
  19. {
  20. // first function to launch
  21. public static void main(String[] args) {
  22. Frame frame = new Frame("SQL manager");
  23. frame.setSize(200,100);
  24. Button b = new Button("Show online");
  25. Button b2 = new Button("Show npc");
  26. frame.add(b);
  27. frame.add(b2);
  28. frame.setLayout(new FlowLayout());
  29. frame.setVisible(true);
  30. frame.addWindowListener(new WindowAdapter(){
  31. public void windowClosing(WindowEvent e){
  32. System.exit(0);
  33. }
  34. //add command for button number 1
  35. // public boolean action(Event e, Object o)
  36. // {
  37. // System.out.println ("Button 1 working!");
  38. // return false;
  39. // }
  40.  
  41.  
  42.  
  43.  
  44. int i=0;
  45. int j=0;
  46. public void init()
  47. {
  48. Button b3= new Button("Hell");
  49. }
  50. public boolean handleEvent (Event e)
  51. { i++;
  52. System.out.println("HandleEvent "+i);
  53. return true;
  54. }
  55. public boolean action(Event e, Object o)
  56. { j++;
  57. System.out.println("action "+j);
  58. return true;
  59. }
  60.  
  61.  
  62.  
  63. {
  64. System.out.println("button 1 pressed\n");
  65. }
  66. });
  67. try {
  68. FileReader fr = new FileReader("zone.txt");
  69. BufferedReader br = new BufferedReader(fr);
  70.  
  71. String s;
  72. while ((s = br.readLine()) != null) {
  73. //System.out.println(s);
  74. String[] items = s.split("\t+");
  75.  
  76. // formatted output, %s - string \n - newline
  77. System.out.printf("%s - %s\n", items[0], items[6]);
  78. }
  79.  
  80.  
  81. Class.forName("com.mysql.jdbc.Driver");
  82.  
  83. String url = "jdbc:mysql://80.240.211.244/c6server";
  84. Connection con = DriverManager.getConnection(url, "Ruzli", "slH59RUwt6711");
  85. // create statement bound to connection
  86. Statement stmt = con.createStatement();
  87.  
  88. // execute query and get resultset ********************************************
  89. ResultSet rs = stmt.executeQuery("SELECT name, id, idtemplate, serverSideName, level from npc ORDER BY id");
  90.  
  91. // reading resultset line by line
  92. while (rs.next()) {
  93. // get information from database row
  94. String name = rs.getString(1);
  95. int id = rs.getInt(2);
  96. int idt = rs.getInt(3);
  97. int serverSideName = rs.getInt(4);
  98. int level = rs.getInt(5);
  99.  
  100. // %d -- decimal number
  101. System.out.printf("%d(%d) - %s - (S.Name = %d) - (level %d)\n", id, idt, name, serverSideName, level);
  102. }
  103.  
  104. System.out.println("query 1 - done");
  105. // starting 2nd query ***************************************************
  106. System.out.println("Starting query 2\n");
  107. //Don't need ResultSet, due its use only for show result, for update use executeUpdate
  108. stmt.executeUpdate("UPDATE characters SET online='1' WHERE account_name = 'botname';");
  109.  
  110. System.out.printf("query 2 - done\n\n");
  111.  
  112. // starting 3nd query ****************************************
  113. System.out.println("Starting query 3\n");
  114. ResultSet rs3 = stmt.executeQuery("SELECT char_name, online, level from characters ORDER BY level");
  115.  
  116. while (rs3.next()) {
  117. // get information from database row
  118. String char_name = rs3.getString(1);
  119. int online = rs3.getInt(2);
  120. int level = rs3.getInt(3);
  121.  
  122. // read and add space's
  123. StringBuilder sb = new StringBuilder(char_name);
  124. for (int i = 0; i < 20 - char_name.length(); i++) sb.append(' ');
  125. char_name = sb.toString();
  126.  
  127. //print result
  128. System.out.printf("%s\t - (online %d) - (level %d)\n", char_name, online, level);
  129. }
  130. System.out.printf("query 3 - done\n\n");
  131. System.out.printf("all query done");
  132.  
  133.  
  134. } catch (FileNotFoundException e) {
  135. System.out.println("Can't find zone.txt");
  136. } catch (Exception e) {
  137. System.out.println(e.toString());
  138. }
  139. }
  140. }
Add Comment
Please, Sign In to add comment