Advertisement
Guest User

Untitled

a guest
Sep 12th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. package org.oscop.nano.main;
  2.  
  3. import android.os.Bundle;
  4. import android.support.v4.app.Fragment;
  5. import android.view.LayoutInflater;
  6. import android.view.View;
  7. import android.view.ViewGroup;
  8. import android.widget.TextView;
  9.  
  10. import org.oscop.nano.R;
  11.  
  12. import java.sql.Connection;
  13. import java.sql.DriverManager;
  14. import java.sql.ResultSet;
  15. import java.sql.Statement;
  16.  
  17. /*
  18.  * Created by dani on 12/09/17.
  19.  */
  20.  
  21. public class MainView extends Fragment {
  22.  
  23.     public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle savedInstanceState) {
  24.         View view = inflater.inflate(R.layout.main_view, group, false);
  25.         Connection connection = null;
  26.         try {
  27.             Class.forName("com.mysql.jdbc.Driver");
  28.             connection = DriverManager.getConnection("jdbc:mysql://10.42.0.1:3306/user", "android", "password");
  29.             Statement statement = connection.createStatement();
  30.             ResultSet resultSet = statement.executeQuery("SELECT * FROM user");
  31.             while (resultSet.next()) {
  32.                 TextView textView = (TextView) view.findViewById(R.id.textView);
  33.                 textView.setText(resultSet.getInt(1) + " " +resultSet.getString(2)+" "+resultSet.getString(3));
  34.             }
  35.         } catch (Exception e) {
  36.             e.printStackTrace();
  37.         }
  38.         return view;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement