Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Connection conexionBD() {
- Connection conexion = null;
- try{
- StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
- StrictMode.setThreadPolicy(policy);
- Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
- conexion = DriverManager.getConnection("jdbc:jtds:sqlserver://192.168.0.10:1433;databasename=speedex;user=usuario;password=123;");
- }
- catch (Exception e) {
- Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
- }
- return conexion;
- }
- public boolean consultarProyecto() {
- paquete = (EditText) findViewById(R.id.txtPaquete);
- boton = (Button) findViewById(R.id.btnBuscar);
- envio = paquete.getText().toString();
- boolean resp = false;
- try{ //Realizar consulta SELECT
- String sql = "SELECT es.estado, en.fechaLlegada, t.transporte, en.precioTotal FROM estado es, envio en, medioTransporte t, paquete p, grupoPaquete g WHERE es.estadoId = en.estadoId AND t.transporteId = en.transporteId AND g.paqueteId = p.paqueteId AND en.grupoId = g.grupoId AND p.paqueteId = ?;";
- PreparedStatement cmd = conexionBD().prepareStatement(sql);
- //Llenar los parametros de la clase
- cmd.setInt(1, Integer.parseInt(envio));
- //Ejecutar la consulta
- //pedira importar la clase ResultSet
- ResultSet rs = cmd.executeQuery();
- //Recorrer la lista de registros
- if(rs.next()){
- resp = true;
- //asignandole a los atributos de la clase
- estado = rs.getString(1);
- fecha = rs.getString(2);
- transporte = rs.getString(3);
- precio = rs.getDouble(4);
- }
- //cerrando conexion
- cmd.close();
- conexionBD().close();
- Toast.makeText(getApplicationContext(), "Consulta exitosa", Toast.LENGTH_LONG).show();
- }
- catch (Exception ex){
- Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
- }
- return resp;
- }
- public void llamarSegundoActiviy(View view) {
- consultarProyecto();
- System.out.println("El estado es " + estado + "/n" + "La fecha es " + fecha + "/n" + "El tipo de transporte es " + transporte + "/n" + "El precio es " + precio);
- Intent intent = new Intent(MainActivity.this, ScrollingActivity.class);
- intent.putExtra("ESTADO", estado);
- intent.putExtra("FECHA", fecha);
- intent.putExtra("TRANSPORTE", transporte);
- intent.putExtra("PRECIO", precio);
- startActivity(intent);
- }
- public class ScrollingActivity extends AppCompatActivity {
- TextView estado, fecha, transporte, precio;
- Integer numPaquete;
- String estado1, fecha1, transporte1;
- Double precio1;
- DecimalFormat formato = new DecimalFormat("$0.00");
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_scrolling);
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
- FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
- estado = (TextView) findViewById(R.id.txtEstado);
- fecha = (TextView) findViewById(R.id.txtFecha);
- transporte = (TextView) findViewById(R.id.txtTransporte);
- precio = (TextView) findViewById(R.id.txtPrecio);
- Intent inten = getIntent();
- Bundle extras = inten.getExtras();
- if(extras != null) {
- estado1 = extras.getString("ESTADO");
- estado.setText(estado1);
- fecha1 = extras.getString("FECHA");
- fecha.setText(fecha1);
- transporte1 = extras.getString("TRANSPORTE");
- transporte.setText(transporte1);
- precio1 = extras.getDouble("ESTADO");
- precio.setText(String.valueOf(formato.format(precio1)));
- }
- else{
- Toast.makeText(getApplicationContext(), "El numero de paquete no existe", Toast.LENGTH_LONG).show();
- Intent intent = new Intent(ScrollingActivity.this, MainActivity.class);
- startActivity(intent);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement