Guest User

Untitled

a guest
Aug 10th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. package proyecto_1;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.SQLException;
  7. import java.util.Scanner;
  8.  
  9. public class ProyectoNuevoCli {
  10. public static void main(String[] args) throws SQLException {
  11. Scanner sc = new Scanner(System.in);
  12.  
  13. System.out.print("Nombre: ");
  14. String nombre = sc.nextLine();
  15. System.out.print("Descripción (opcional): ");
  16. String descripcion = sc.nextLine();
  17. System.out.print("Fecha de inicio (YYYY-MM-DD): ");
  18. String fecha_inicio = sc.nextLine();
  19. System.out.print("Fecha de finalización (YYYY-MM-DD): ");
  20. String fecha_fin = sc.nextLine();
  21. System.out.print("Presupuesto: ");
  22. float presupuesto = sc.nextFloat();
  23. System.out.print("Retorno esperado: ");
  24. float retorno = sc.nextFloat();
  25.  
  26. Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/quat_dev?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC", "root", "****");
  27.  
  28. String query = "insert into proyectos " +
  29. "(nombre, descripcion, fecha_inicio, fecha_fin, presupuesto, retorno) " +
  30. "values (?, ?, ?, ?, ?, ?)";
  31.  
  32. PreparedStatement st = conn.prepareStatement(query);
  33.  
  34. st.setString(1, nombre);
  35. st.setString(2, descripcion);
  36. st.setString(3, fecha_inicio);
  37. st.setString(4, fecha_fin);
  38. st.setFloat(5, presupuesto);
  39. st.setFloat(6, retorno);
  40.  
  41. boolean fail = st.execute();
  42.  
  43. System.out.printf("Resultado: %s\n", fail ? "Error" : "Correcto");
  44.  
  45. }
  46. }
Add Comment
Please, Sign In to add comment