Advertisement
Guest User

Untitled

a guest
Feb 10th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3. @Override
  4. protected void onCreate(Bundle savedInstanceState) {
  5. super.onCreate(savedInstanceState);
  6. setContentView(R.layout.activity_main);
  7. new Connect();
  8. TextView myTextView = (TextView) findViewById(R.id.text);
  9. myTextView.setText();
  10.  
  11. }
  12.  
  13. public class Connect extends AsyncTask<Context, Integer, Long> {
  14.  
  15. protected Long doInBackground(Context... contexts) {
  16.  
  17. Connection connection;
  18. String query = "SELECT * FROM Scraped WHERE Category='Hazard'";
  19. try {
  20. Class.forName("com.mysql.jdbc.Driver");
  21. connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1/scrapedb", "root", "root");
  22.  
  23. Statement statement = connection.createStatement();
  24. ResultSet resultSet = statement.executeQuery(query);
  25.  
  26. while(resultSet.next()){
  27.  
  28. String contents = resultSet.getString(1);
  29. //what do i do here to get data and display it on the
  30. //textview
  31. }
  32.  
  33.  
  34. } catch (ClassNotFoundException e) {
  35. e.printStackTrace();
  36. } catch (SQLException e) {
  37. e.printStackTrace();
  38. }
  39. }
  40. }
  41. }
  42.  
  43. <?xml version="1.0" encoding="utf-8"?>
  44. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  45. xmlns:tools="http://schemas.android.com/tools"
  46. android:id="@+id/activity_main"
  47. android:layout_width="match_parent"
  48. android:layout_height="match_parent"
  49. android:paddingBottom="@dimen/activity_vertical_margin"
  50. android:paddingLeft="@dimen/activity_horizontal_margin"
  51. android:paddingRight="@dimen/activity_horizontal_margin"
  52. android:paddingTop="@dimen/activity_vertical_margin"
  53. tools:context="com.example.boneyflesh.testconnection.MainActivity">
  54.  
  55. <TextView
  56. android:layout_width="wrap_content"
  57. android:layout_height="wrap_content"
  58. android:id="@+id/text" />
  59. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement