Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.musyrif.javasql;
- import android.os.AsyncTask;
- import android.widget.TextView;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Statement;
- /**
- * Created by musyrif on 15-Oct-17.
- */
- class get extends AsyncTask{
- private TextView text;
- public get(TextView text)
- {
- this.text = text;
- }
- @Override
- protected String doInBackground(Object[] objects) {
- try{
- String result = new String();
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://192.168.0.2:3306/mydb","myuser","mypass");
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery("select * from test");
- while(rs.next()) {
- result += "|" + (rs.getFloat(1) + " " + rs.getFloat(2)).toString();
- }
- con.close();
- return result;
- }catch(Exception e){
- System.out.println(e);
- return e.toString();
- }
- }
- protected void onPostExecute(String result) {
- text.setText(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement