Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. package pkgConexion;
  2.  
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.util.Date;
  6.  
  7.  
  8. public class clsNatural {
  9.  
  10. private String id;
  11. private String nombre;
  12. private Date edad;
  13. private String sexo;
  14. private pkgConexion.clsConn conn = new pkgConexion.clsConn();
  15.  
  16. public String getId() {
  17. return id;
  18. }
  19.  
  20. public void setId(String id) {
  21. this.id = id;
  22. }
  23.  
  24. public String getNombre() {
  25. return nombre;
  26. }
  27.  
  28. public void setNombre(String nombre) {
  29. this.nombre = nombre;
  30. }
  31.  
  32. public Date getedad() {
  33. return edad;
  34. }
  35.  
  36. public void setedad(Date edad) {
  37. this.edad = edad;
  38. }
  39.  
  40. public String getsexo() {
  41. return sexo;
  42. }
  43.  
  44. public void setsexo(String sexo) {
  45. this.sexo = sexo;
  46. }
  47.  
  48. public pkgConexion.clsConn getConn() {
  49. return conn;
  50. }
  51.  
  52. public void setConn(pkgConexion.clsConn conn) {
  53. this.conn = conn;
  54. }
  55.  
  56. public String Insertar(){
  57. String sql="INSERT INTO pnatural VALUES('"+this.id+"','"+this.nombre+"','"+this.edad+"','"+this.sexo+"')";
  58. if(Verificar(this.id)==true)
  59. return "0";
  60. else{
  61. if(getConn().insertar(sql)==null)
  62. return "1";
  63. }
  64. return "-1";
  65. }
  66.  
  67. public boolean Verificar(String key){
  68. String sql="SELECT * From pnatural where cedula='"+key.toString()+"'";
  69. if(getConn().verificar(sql)==1)
  70. return true;
  71. return false;
  72. }
  73.  
  74. public String consultar() throws SQLException{
  75. String sql="SELECT * from pnatural";
  76. ResultSet rs=getConn().consultar(sql);
  77. String sb="";
  78. int x=1;
  79. sb+="<center><table border=1><tr><td>Cedula</td><td>Nombre</td><td>Edad</td><td>Sexo</td></tr>";
  80. while(rs.next()){
  81. sb+="<tr><td><input type='text' value="+rs.getString(1)+" disabled='true' name='textbox"+x+"'></td><td>"+rs.getString(2)+"</td><td>"+rs.getString(3)+"</td><td>"+rs.getString(4)+"</td></tr>";
  82. x++;
  83. }
  84. sb+="</table></center>";
  85. return sb;
  86. }
  87.  
  88. public String modificar(String key) {
  89. if (Verificar(key) == true) {
  90. String sql = "UPDATE pnatural set nombre='" + nombre + "' ,pedad='"+edad+"' where cedula='" + key.toString() + "'";
  91. if (conn.actualizar(sql) == 1) {
  92. return "Modificado con éxito, verifique";
  93. }
  94. }
  95. return "Problemas para modificar";
  96. }
  97.  
  98. public boolean eliminar(String key) {
  99. if (Verificar(key) == true) {
  100. String sql = "DELETE from pnatural where cedula='" + key.toString() + "'";
  101. if (conn.actualizar(sql) == 1) {
  102. return true;
  103. }
  104. }
  105. return false;
  106. }
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement