Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static ArrayList<Centro> centros_search;
- centros_search= new ArrayList<Centro>();
- String myDriver = "com.mysql.jdbc.Driver";
- String myUrl = "jdbc:mysql://[IP]:3306/";
- Connection conn = null;
- try {
- Class.forName(myDriver);
- conn = DriverManager.getConnection(myUrl, "user", "password");
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- String sql = "SELECT * FROM `Centro`";
- // create the java statement
- Statement stmt = null;
- ResultSet rs = null;
- try {
- stmt = conn.createStatement();
- rs = stmt.executeQuery(sql);
- //STEP 5: Extract data from result set
- while(rs.next()){
- //Retrieve by column name
- String id = rs.getString("centreID");
- String name = rs.getString("centreName");
- String dir = rs.getString("centreDir");
- String number = rs.getString("centreNumber");
- //System.out.println(id+"----"+name+"----"+dir+"----"+number);
- Centro c = new Centro(id,name,dir,number);
- centros_search.add(c);
- }
- rs.close();
- conn.close();
- stmt.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- doThat();
- }
- for (Centro c: centros_search){
- System.out.println(c.centreID+"----"+c.centreName+"----"+c.centreDir+"----"+c.centreNumber);
- }
- //UI ELEMENTS
- private static RecyclerView rv;
- static LinearLayoutManager llm;
- Button b1;
- public static ArrayList<Centro> centros_search;
- static RVAdapter adapter;
- Centro c;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_searchable);
- centros_search = new ArrayList<Centro>();
- rv = (RecyclerView)findViewById(R.id.rvSearch);
- llm = new LinearLayoutManager(this.getApplicationContext());
- Centro c = new Centro("lol","lols","cccccc","176378238");
- centros_search.add(c);
- b1 = (Button) findViewById(R.id.button_search);
- b1.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- do_search();
- }
- });
- }
- private static void do_search() {
- centros_search.clear();
- Centro c1 = new Centro("lol2","lol2","cccccc","176378238");
- centros_search.add(c1);
- try {
- String myDriver = "com.mysql.jdbc.Driver";
- String myUrl = "jdbc:mysql://[IP]:3306/meapuntoapp";
- Connection conn = DriverManager.getConnection(myUrl, "user", "password");
- Class.forName(myDriver);
- String sql = "SELECT * FROM `Centro`";
- // create the java statement
- Statement stmt = null;
- ResultSet rs = null;
- stmt = conn.createStatement();
- rs = stmt.executeQuery(sql);
- //STEP 5: Extract data from result set
- while(rs.next()){
- //Retrieve by column name
- String id = rs.getString("centreID");
- String name = rs.getString("centreName");
- String dir = rs.getString("centreDir");
- String number = rs.getString("centreNumber");
- System.out.println(id+"----"+name+"----"+dir+"----"+number);
- Centro c = new Centro(id,name,dir,number);
- centros_search.add(0,c);
- nonSense(c);
- }
- rs.close();
- conn.close();
- stmt.close();
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- Centro c3 = new Centro("lol2","lol3","cccccc","176378238");
- centros_search.add(c3);
- adapter = new RVAdapter(centros_search);
- rv.setAdapter(adapter);
- rv.setLayoutManager(llm);
- }
- private static void nonSense(Centro c) {
- centros_search.add(c);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement