Advertisement
Guest User

Untitled

a guest
Oct 15th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. package com.example.musyrif.javasql;
  2.  
  3. import android.os.AsyncTask;
  4. import android.widget.TextView;
  5.  
  6.  
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.ResultSet;
  10. import java.sql.Statement;
  11.  
  12. /**
  13.  * Created by musyrif on 15-Oct-17.
  14.  */
  15.  
  16. class get extends AsyncTask{
  17. private TextView text;
  18.     public get(TextView text)
  19.     {
  20.         this.text = text;
  21.     }
  22.     @Override
  23.     protected String doInBackground(Object[] objects) {
  24.         try{
  25.             String result = new String();
  26.             Class.forName("com.mysql.jdbc.Driver");
  27.             Connection con = DriverManager.getConnection("jdbc:mysql://192.168.0.2:3306/mydb","myuser","mypass");
  28.             Statement stmt = con.createStatement();
  29.             ResultSet rs = stmt.executeQuery("select * from test");
  30.             while(rs.next()) {
  31.                 result += "|" + (rs.getFloat(1) + " " + rs.getFloat(2)).toString();
  32.             }
  33.             con.close();
  34.             return result;
  35.         }catch(Exception e){
  36.             System.out.println(e);
  37.             return e.toString();
  38.         }
  39.  
  40.     }
  41.     protected void onPostExecute(String result) {
  42.         text.setText(result);
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement