Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.IOException;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.awt.*;
- import java.applet.*;
- import java.awt.event.*;
- /** guide for event buttons...
- public boolean action(Event e, Object o) ..
- and listbox */
- // ... extends Applet, for handle button events
- public class first extends Applet
- {
- // first function to launch
- public static void main(String[] args) {
- Frame frame = new Frame("SQL manager");
- frame.setSize(200,100);
- Button b = new Button("Show online");
- Button b2 = new Button("Show npc");
- frame.add(b);
- frame.add(b2);
- frame.setLayout(new FlowLayout());
- frame.setVisible(true);
- frame.addWindowListener(new WindowAdapter(){
- public void windowClosing(WindowEvent e){
- System.exit(0);
- }
- //add command for button number 1
- // public boolean action(Event e, Object o)
- // {
- // System.out.println ("Button 1 working!");
- // return false;
- // }
- int i=0;
- int j=0;
- public void init()
- {
- Button b3= new Button("Hell");
- }
- public boolean handleEvent (Event e)
- { i++;
- System.out.println("HandleEvent "+i);
- return true;
- }
- public boolean action(Event e, Object o)
- { j++;
- System.out.println("action "+j);
- return true;
- }
- {
- System.out.println("button 1 pressed\n");
- }
- });
- try {
- FileReader fr = new FileReader("zone.txt");
- BufferedReader br = new BufferedReader(fr);
- String s;
- while ((s = br.readLine()) != null) {
- //System.out.println(s);
- String[] items = s.split("\t+");
- // formatted output, %s - string \n - newline
- System.out.printf("%s - %s\n", items[0], items[6]);
- }
- Class.forName("com.mysql.jdbc.Driver");
- String url = "jdbc:mysql://80.240.211.244/c6server";
- Connection con = DriverManager.getConnection(url, "Ruzli", "slH59RUwt6711");
- // create statement bound to connection
- Statement stmt = con.createStatement();
- // execute query and get resultset ********************************************
- ResultSet rs = stmt.executeQuery("SELECT name, id, idtemplate, serverSideName, level from npc ORDER BY id");
- // reading resultset line by line
- while (rs.next()) {
- // get information from database row
- String name = rs.getString(1);
- int id = rs.getInt(2);
- int idt = rs.getInt(3);
- int serverSideName = rs.getInt(4);
- int level = rs.getInt(5);
- // %d -- decimal number
- System.out.printf("%d(%d) - %s - (S.Name = %d) - (level %d)\n", id, idt, name, serverSideName, level);
- }
- System.out.println("query 1 - done");
- // starting 2nd query ***************************************************
- System.out.println("Starting query 2\n");
- //Don't need ResultSet, due its use only for show result, for update use executeUpdate
- stmt.executeUpdate("UPDATE characters SET online='1' WHERE account_name = 'botname';");
- System.out.printf("query 2 - done\n\n");
- // starting 3nd query ****************************************
- System.out.println("Starting query 3\n");
- ResultSet rs3 = stmt.executeQuery("SELECT char_name, online, level from characters ORDER BY level");
- while (rs3.next()) {
- // get information from database row
- String char_name = rs3.getString(1);
- int online = rs3.getInt(2);
- int level = rs3.getInt(3);
- // read and add space's
- StringBuilder sb = new StringBuilder(char_name);
- for (int i = 0; i < 20 - char_name.length(); i++) sb.append(' ');
- char_name = sb.toString();
- //print result
- System.out.printf("%s\t - (online %d) - (level %d)\n", char_name, online, level);
- }
- System.out.printf("query 3 - done\n\n");
- System.out.printf("all query done");
- } catch (FileNotFoundException e) {
- System.out.println("Can't find zone.txt");
- } catch (Exception e) {
- System.out.println(e.toString());
- }
- }
- }
Add Comment
Please, Sign In to add comment