Advertisement
Guest User

Untitled

a guest
Oct 31st, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. ArrayAdapter NoCoreAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, data);
  2.  
  3. ruta = (Spinner) ruta.findViewById(R.id.spinner2);
  4.  
  5. public class Valorar extends Fragment {
  6.  
  7. Connection con;
  8. Spinner ruta;
  9. PreparedStatement stmt;
  10. ResultSet rs;
  11.  
  12.  
  13. @Override
  14. public void onCreate(Bundle savedInstanceState) {
  15. super.onCreate(savedInstanceState);
  16.  
  17. String ip = "mssql4.gear.host";
  18. String db = "ciclomapp1";
  19. String un = "ciclomapp1";
  20. String passwords = "Mk36-9DX-580";
  21. ruta = (Spinner) ruta.findViewById(R.id.spinner2);
  22.  
  23. String query = "select nombre from Rutas";
  24. try {
  25. con = connectionclass (un, passwords, db, ip);
  26. stmt = con.prepareStatement(query);
  27. rs = stmt.executeQuery();
  28. ArrayList<String> data = new ArrayList<String>();
  29. while (rs.next()) {
  30. String id = rs.getString("nombre");
  31. data.add(id);
  32. }
  33. String[] array = data.toArray(new String[0]);
  34. ArrayAdapter NoCoreAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, data);
  35. ruta.setAdapter(NoCoreAdapter);
  36.  
  37. } catch (SQLException e) {
  38.  
  39. e.printStackTrace();
  40.  
  41. }
  42.  
  43. }
  44.  
  45.  
  46. @SuppressLint("NewApi")
  47. public Connection connectionclass(String user, String password, String database, String server)
  48. {
  49. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
  50. StrictMode.setThreadPolicy(policy);
  51. Connection connection = null;
  52. String ConnectionURL = null;
  53. try
  54. {
  55. Class.forName("net.sourceforge.jtds.jdbc.Driver");
  56. ConnectionURL = "jdbc:jtds:sqlserver://" + server +"/"+ database + ";user=" + user+ ";password=" + password + ";";
  57. connection = DriverManager.getConnection(ConnectionURL);
  58. }
  59. catch (SQLException se)
  60. {
  61. Log.e("error here 1 : ", se.getMessage());
  62. }
  63. catch (ClassNotFoundException e)
  64. {
  65. Log.e("error here 2 : ", e.getMessage());
  66. }
  67. catch (Exception e)
  68. {
  69. Log.e("error here 3 : ", e.getMessage());
  70. }
  71. return connection;
  72. }
  73.  
  74.  
  75. @Override
  76. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  77. Bundle savedInstanceState) {
  78. // Inflate the layout for this fragment
  79. return inflater.inflate(R.layout.fragment_valorar, container, false);
  80. }
  81.  
  82. public interface OnFragmentInteractionListener {
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement