Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- new Connect();
- TextView myTextView = (TextView) findViewById(R.id.text);
- myTextView.setText();
- }
- public class Connect extends AsyncTask<Context, Integer, Long> {
- protected Long doInBackground(Context... contexts) {
- Connection connection;
- String query = "SELECT * FROM Scraped WHERE Category='Hazard'";
- try {
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1/scrapedb", "root", "root");
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(query);
- while(resultSet.next()){
- String contents = resultSet.getString(1);
- //what do i do here to get data and display it on the
- //textview
- }
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/activity_main"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context="com.example.boneyflesh.testconnection.MainActivity">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/text" />
- </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement