Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.oscop.nano.main;
- import android.os.Bundle;
- import android.support.v4.app.Fragment;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.TextView;
- import org.oscop.nano.R;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Statement;
- /*
- * Created by dani on 12/09/17.
- */
- public class MainView extends Fragment {
- public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.main_view, group, false);
- Connection connection = null;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection("jdbc:mysql://10.42.0.1:3306/user", "android", "password");
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery("SELECT * FROM user");
- while (resultSet.next()) {
- TextView textView = (TextView) view.findViewById(R.id.textView);
- textView.setText(resultSet.getInt(1) + " " +resultSet.getString(2)+" "+resultSet.getString(3));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return view;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement