Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. package restaurantelospavorreales;
  2. import java.sql.*;
  3. import javax.swing.JOptionPane;
  4.  
  5. /**
  6. *
  7. * @author luisricardo
  8. */
  9. public class DB_Conecttion {
  10. public Connection Conexion(){
  11. Connection Con = null;
  12. try {
  13. Class.forName("com.mysql.jdbc.Driver");
  14. Con = DriverManager.getConnection("jdbc:mysql://localhost:8080/pavorreales", "root", "");
  15. } catch (Exception e) {
  16. JOptionPane.showMessageDialog(null, "Se presento el error: " + e);
  17. }
  18. return Con;
  19. }
  20. }
  21.  
  22. package restaurantelospavorreales;
  23. import java.util.LinkedList;
  24. import java.sql.*;
  25. import javax.swing.JOptionPane;
  26.  
  27. /**
  28.  
  29. * @author luisricardo
  30. */
  31. public class BuscarProducto {
  32. public LinkedList Producto(int Identificador, String Tipo, int Cantidad, int Mesa){
  33. LinkedList Datos = new LinkedList();
  34. Datos.add(Mesa);
  35. String Query;
  36. Query = "SELECT ID, Nombre, Precio FROM '" + Tipo + "' WHERE ID = " + Identificador ; //Se construye el Query
  37. //Se realiza la conexion
  38. try {
  39. ResultSet Res = new DB_Conecttion().Conexion().createStatement().executeQuery(Query);
  40.  
  41. Datos.addLast(Res.getString(1));
  42. Datos.addLast(Res.getString(2));
  43. Datos.addLast(Res.getString(3));
  44.  
  45. } catch (Exception e) {
  46. JOptionPane.showMessageDialog(null,"Error en la conexion a la DB :" + e);
  47. }
  48.  
  49. return Datos;
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement