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;
- public class first
- {
- // first function to launch
- public static void main(String[] args) {
- 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");
- ResultSet rs2 = stmt.executeQuery("SELECT char_name, online, level from characters ORDER BY level");
- while (rs2.next()) {
- // get information from database row
- String char_name = rs2.getString(1);
- int online = rs2.getInt(2);
- int level = rs2.getInt(3);
- //print result
- System.out.printf("%s\t - (online %d) - (level %d)\n", char_name, online, level);
- }
- System.out.printf("query 2 - 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