Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ArrayAdapter NoCoreAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, data);
- ruta = (Spinner) ruta.findViewById(R.id.spinner2);
- public class Valorar extends Fragment {
- Connection con;
- Spinner ruta;
- PreparedStatement stmt;
- ResultSet rs;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- String ip = "mssql4.gear.host";
- String db = "ciclomapp1";
- String un = "ciclomapp1";
- String passwords = "Mk36-9DX-580";
- ruta = (Spinner) ruta.findViewById(R.id.spinner2);
- String query = "select nombre from Rutas";
- try {
- con = connectionclass (un, passwords, db, ip);
- stmt = con.prepareStatement(query);
- rs = stmt.executeQuery();
- ArrayList<String> data = new ArrayList<String>();
- while (rs.next()) {
- String id = rs.getString("nombre");
- data.add(id);
- }
- String[] array = data.toArray(new String[0]);
- ArrayAdapter NoCoreAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, data);
- ruta.setAdapter(NoCoreAdapter);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- @SuppressLint("NewApi")
- public Connection connectionclass(String user, String password, String database, String server)
- {
- StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
- StrictMode.setThreadPolicy(policy);
- Connection connection = null;
- String ConnectionURL = null;
- try
- {
- Class.forName("net.sourceforge.jtds.jdbc.Driver");
- ConnectionURL = "jdbc:jtds:sqlserver://" + server +"/"+ database + ";user=" + user+ ";password=" + password + ";";
- connection = DriverManager.getConnection(ConnectionURL);
- }
- catch (SQLException se)
- {
- Log.e("error here 1 : ", se.getMessage());
- }
- catch (ClassNotFoundException e)
- {
- Log.e("error here 2 : ", e.getMessage());
- }
- catch (Exception e)
- {
- Log.e("error here 3 : ", e.getMessage());
- }
- return connection;
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- return inflater.inflate(R.layout.fragment_valorar, container, false);
- }
- public interface OnFragmentInteractionListener {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement