elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a Git (Primera Parte)


  Mostrar Mensajes
Páginas: [1] 2
1  Programación / Desarrollo Web / Re: Problemas con modal bootstrap, javascript y php. en: 6 Agosto 2016, 02:24 am
algo, pero no importa :c

ahora tengo problemas con el actualizar :c
2  Programación / Desarrollo Web / Re: Problemas con modal bootstrap, javascript y php. en: 3 Agosto 2016, 02:41 am
 :-( :-( :-( :-( :-(
3  Programación / Desarrollo Web / Problemas con modal bootstrap, javascript y php. en: 30 Julio 2016, 21:19 pm
Hola mi nombre es sebastían y soy nuevo en el mundo de la programación, quisiera hacer una consulta.


1.- Trato de realizar una confirmación al eliminar la cual el modal no me aparece (o permanece muy muy poco tiempo).

2.- La idea es tratar de mandar a buscar el modal de confirmación antes de eliminar un registro, sin embargo, no me aparece, mil disculpas y gracias por su tiempo.

Nota: creo que el problema está en el script :c

Código:
 
       <script>
       $("#eliminar").on("click", function(){
 
   if (window.location.href = "administracion.php?id_PersonaAEliminar=<?php echo $personal->getId_persona(); ?>" ;

){

return true;
 } else {

      return false;
}

});
    </script>    

<td><a href="administracion.php?id_PersonaAEliminar=<?php echo $personal->getId_persona(); ?>" >
      
  <p data-placement="top" data-toggle="tooltip" title="Eliminar">
<button class="btn btn-danger btn-xs"  data-title="Delete"
data-toggle="modal" data-target="#eliminar" >
<span class="glyphicon glyphicon-trash"></span></button></p>
       </a></td>
  
  
  
</tr>
    
   <?php
                        
                      
                        
            }
            ?>
                                                    
     </table>
    
    
</div>

<?php

 
 
?>  
 
 
    
  <div class="modal fade" id="eliminar" tabindex="-1" role="dialog" aria-labelledby="myModalLabelzz" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
            
                <div class="modal-header">
                    
                    <h4 class="modal-title">Eliminar</h4>
                </div>
            
                <div class="modal-body">
                    <p>¿Desea eliminar el registro?</p>
                    
                </div>
                
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
                    <a class="btn btn-danger btn-ok">Eliminar</a>
                </div>
            </div>
        </div>
    </div>





4  Programación / Java / Re: AYUDA SOBRE CODIGO (UPDATE) ES LO ULTIMO QUE ME FALTA :C en: 16 Noviembre 2013, 23:59 pm
1.- ESTAS EN LO CIERTO.. NADIE ESTA OBLIGADO, PERO POR ALGO SE POSTEA, ES PARA AYUDAR, SOBRE TODO LOS QUE SABEN MÁS, COMO ORIENTAR ETC., ESE ES EL GRAN OBJETIVO DE ESTE FORO, ENTRE OTROS....

2.- SI NO SE APOYA, NO COMENTE. SOBRE TODO EN MALA ONDA.


3.- COMO TENGO MIS PRINCIPIOS, MUCHAS GRACIAS.

4.- VERIFICANDO CODIGO
5  Programación / Java / AYUDA SOBRE CODIGO (UPDATE) ES LO ULTIMO QUE ME FALTA :C en: 16 Noviembre 2013, 21:22 pm
Hola amigos estoy fabricando un codigo pero mi problema es que quiero actualizar los datos desde una tabla a MYSQL, o sea que yo al clickear el registro sobre la tabla, con el boton MODIFICAR, tambien se actualizen de mi BD.

PARA MAYOR ILUSTRACION EL METODO ESTA EN LA LINEA 267.

GRACIAS POR SU AYUDA.... (SÓLO A LOS QUE AYUDAN  :o)

Código
  1. package formularios;
  2.  
  3. import javax.swing.JFrame;
  4. import javax.swing.JPanel;
  5. import javax.swing.table.DefaultTableModel;
  6. import javax.swing.JLabel;
  7. import javax.swing.JOptionPane;
  8. import javax.swing.JTextField;
  9. import javax.swing.JButton;
  10.  
  11. import java.awt.Color;
  12. import java.awt.Toolkit;
  13. import java.awt.event.ActionListener;
  14. import java.awt.event.ActionEvent;
  15. import java.sql.*;
  16.  
  17. import javax.swing.JTable;
  18. import javax.swing.JScrollPane;
  19. import java.awt.event.KeyAdapter;
  20. import java.awt.event.KeyEvent;
  21.  
  22. public class ing_ani extends JFrame {
  23.  
  24. private JTable t_datos;
  25.  
  26. private JPanel contentPane;
  27. private JTextField t_nom;
  28. private JTextField t_eda;
  29. private JTextField t_col;
  30. private JTextField t_tip;
  31. private JTextField filtro;
  32.  
  33.  
  34. // DECLARAMOS Y DAMOS ACCIONES
  35.  
  36. public ing_ani() {
  37.  
  38. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  39. setBounds(100, 100, 563, 459);
  40. setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\Sebastian\\Desktop\\huella.jpg"));
  41. setTitle("Animales");
  42. contentPane = new JPanel();
  43. setContentPane(contentPane);
  44. contentPane.setLayout(null);
  45.  
  46. JLabel lblIngresoAnimales = new JLabel("Ingreso Animales");
  47. lblIngresoAnimales.setBounds(227, 11, 116, 14);
  48. contentPane.add(lblIngresoAnimales);
  49.  
  50. JLabel lblNombre = new JLabel("Nombre");
  51. lblNombre.setBounds(29, 49, 66, 14);
  52. contentPane.add(lblNombre);
  53.  
  54. JLabel lblEdad = new JLabel("Edad");
  55. lblEdad.setBounds(29, 92, 66, 14);
  56. contentPane.add(lblEdad);
  57.  
  58. JLabel lblColor = new JLabel("Color");
  59. lblColor.setBounds(29, 132, 66, 14);
  60. contentPane.add(lblColor);
  61.  
  62. JLabel lblTipo = new JLabel("Tipo");
  63. lblTipo.setBounds(29, 172, 66, 14);
  64. contentPane.add(lblTipo);
  65.  
  66. JLabel lblConsultarMasivo = new JLabel("Consultar masivo");
  67. lblConsultarMasivo.setBounds(42, 221, 107, 14);
  68. contentPane.add(lblConsultarMasivo);
  69.  
  70. JLabel lblBsquedaPorCriterio = new JLabel("B\u00FAsqueda por nombre");
  71. lblBsquedaPorCriterio.setBounds(42, 254, 140, 14);
  72. contentPane.add(lblBsquedaPorCriterio);
  73.  
  74. t_nom = new JTextField();
  75. t_nom.setBounds(105, 46, 267, 20);
  76. contentPane.add(t_nom);
  77. t_nom.setColumns(10);
  78.  
  79. t_eda = new JTextField();
  80. t_eda.setBounds(105, 89, 267, 20);
  81. contentPane.add(t_eda);
  82. t_eda.setColumns(10);
  83.  
  84. t_col = new JTextField();
  85. t_col.setBounds(105, 129, 267, 20);
  86. contentPane.add(t_col);
  87. t_col.setColumns(10);
  88.  
  89. t_tip = new JTextField();
  90. t_tip.setBounds(105, 169, 267, 20);
  91. contentPane.add(t_tip);
  92. t_tip.setColumns(10);
  93.  
  94. // BOTON LIMPIAR
  95. JButton btnLimpiar = new JButton("Limpiar");
  96. btnLimpiar.addActionListener(new ActionListener() {
  97. public void actionPerformed(ActionEvent arg0) {
  98. limpiar();
  99. }
  100. });
  101. btnLimpiar.setBounds(419, 35, 89, 23);
  102. contentPane.add(btnLimpiar);
  103. // TERMINO BOTON LIMPIAR
  104.  
  105. // BOTON GRABAR
  106. JButton btnGrabar = new JButton("Grabar");
  107. btnGrabar.addActionListener(new ActionListener() {
  108. public void actionPerformed(ActionEvent e) {
  109. grabar();
  110. limpiar();
  111. cargar();
  112. }
  113. });
  114. btnGrabar.setBounds(419, 74, 89, 23);
  115. contentPane.add(btnGrabar);
  116. // / TERMINO BOTON GRABAR
  117.  
  118. // BOTON MODIFICAR
  119. JButton btnModificar = new JButton("Modificar");
  120. btnModificar.addActionListener(new ActionListener() {
  121. public void actionPerformed(ActionEvent e) {
  122. modificar();
  123. }
  124. });
  125. btnModificar.setBounds(419, 109, 89, 23);
  126. contentPane.add(btnModificar);
  127.  
  128. // / TERMINO BOTON MODIFICAR
  129.  
  130. // INICIO BOTON ELIMINAR
  131. JButton btnEliminar = new JButton("Eliminar");
  132. btnEliminar.addActionListener(new ActionListener() {
  133. public void actionPerformed(ActionEvent e) {
  134. eliminar();
  135. }
  136.  
  137. });
  138. btnEliminar.setBounds(419, 143, 89, 23);
  139. contentPane.add(btnEliminar);
  140. // TERMINO BOTON ELIMINAR
  141.  
  142. // INICIO BOTON CONSULTAR
  143. JButton btnConsultar = new JButton("Consultar");
  144. btnConsultar.addActionListener(new ActionListener() {
  145. public void actionPerformed(ActionEvent e) {
  146. cargar();
  147. JOptionPane.showMessageDialog(null, "Tabla Actualizada");
  148. }
  149. });
  150. btnConsultar.setBounds(207, 217, 89, 23);
  151. contentPane.add(btnConsultar);
  152. // TERMINO DE BOTON CONSULTAR
  153.  
  154. // INICIO BOTON SALIR
  155. JButton btnSalir = new JButton("Salir");
  156. btnSalir.addActionListener(new ActionListener() {
  157. public void actionPerformed(ActionEvent e) {
  158. salir();
  159. }
  160. });
  161. btnSalir.setBounds(419, 177, 89, 23);
  162. contentPane.add(btnSalir);
  163. // TERMINO BOTON SALIR
  164.  
  165. // CREACION DE TABLA
  166.  
  167. JScrollPane scrollPane = new JScrollPane();
  168. scrollPane.setBounds(42, 282, 459, 127);
  169. contentPane.add(scrollPane);
  170. t_datos = new JTable();
  171. scrollPane.setViewportView(t_datos);
  172.  
  173. // ACCION JTEXT BUSQUEDA POR NOMBRE
  174.  
  175. filtro = new JTextField();
  176. filtro.addKeyListener(new KeyAdapter() {
  177.  
  178. public void keyReleased(KeyEvent arg0) {
  179. cargarfil(filtro.getText());
  180. }
  181. });
  182. filtro.setBounds(207, 251, 134, 20);
  183. contentPane.add(filtro);
  184. filtro.setColumns(10);
  185.  
  186. // TERMINO ACCION JTEXT BUSQUEDA POR NOMBRE
  187.  
  188. // COLORES AL ENCABEZADO DE UN JTABLE Y LETRA
  189. t_datos.getTableHeader().setBackground(Color.DARK_GRAY);
  190. t_datos.getTableHeader().setForeground(Color.WHITE);
  191.  
  192. // TERMINO TABLA
  193.  
  194. // CARGA LA TABLA CON SUS REGISTROS AL INICIAR LA VENTANA
  195. cargar();
  196. cargarfil("");
  197. }
  198.  
  199. // INICIO METODO LIMPIAR
  200. void limpiar() {
  201. t_nom.setText("");
  202. t_eda.setText("");
  203. t_col.setText("");
  204. t_tip.setText("");
  205.  
  206. }
  207.  
  208. // FIN METODO LIMPIAR
  209.  
  210. // INICIO DE METODO GRABAR
  211.  
  212. void grabar() {
  213. try {
  214. conectar cc = new conectar();
  215. Connection cn = cc.conexion();
  216. String nom, eda, col, tip;
  217. String sql = "";
  218. nom = t_nom.getText();
  219. eda = t_eda.getText();
  220. col = t_col.getText();
  221. tip = t_tip.getText();
  222. sql = "INSERT INTO animales (nom_ani, eda_ani, col_ani, tip_ani) VALUES (?,?,?,?)";
  223.  
  224. PreparedStatement pst = cn.prepareStatement(sql);
  225.  
  226. pst.setString(1, nom);
  227. pst.setString(2, eda);
  228. pst.setString(3, col);
  229. pst.setString(4, tip);
  230. pst.executeUpdate();
  231.  
  232. JOptionPane.showMessageDialog(null, "Registrado Grabado con exito");
  233.  
  234. } catch (SQLException e1) {
  235. JOptionPane.showMessageDialog(null, "ERROR");
  236. }
  237.  
  238. }
  239. // FIN DE METODO GRABAR
  240.  
  241.  
  242. // INICIO DE METODO ELIMINAR
  243. void eliminar() {
  244. try {
  245.  
  246. int registros = t_datos.getSelectedRow();
  247. String sql = "";
  248. sql = "DELETE FROM animales where cod_ani="+ t_datos.getValueAt(registros, 0);
  249. conectar cc = new conectar();
  250. Connection cn = cc.conexion();
  251. PreparedStatement pst = cn.prepareStatement(sql);
  252. int n = pst.executeUpdate(sql);
  253. if (n > 0) {
  254. cargar();
  255. }
  256. JOptionPane.showMessageDialog(null, "Datos eliminados");
  257.  
  258. } catch (Exception e1) {
  259. JOptionPane.showMessageDialog(null, "ERROR" + e1.getMessage());
  260. }
  261. }
  262.  
  263. // FIN DE METODO ELIMINAR
  264.  
  265.  
  266. // INICIO DE METODO MODIFICAR
  267. void modificar() {
  268. try {
  269. int registros = t_datos.getSelectedRow();
  270.  
  271. String sql ="";
  272. sql= "UPDATE FROM animales nom_ani, eda_ani , col_ani , tip_ani="+"WHERE cod_ani="+t_datos.getValueAt (registros,0);
  273. conectar cc = new conectar();
  274. Connection cn = cc.conexion();
  275. String nom, eda, col, tip;
  276.  
  277. nom = t_nom.getText();
  278. eda = t_eda.getText();
  279. col = t_col.getText();
  280. tip = t_tip.getText();
  281.  
  282. PreparedStatement pst = cn.prepareStatement(sql);
  283. pst.setString (1, nom);
  284. pst.setString (2, eda);
  285. pst.setString (3, col);
  286. pst.setString (4, tip);
  287.  
  288.  
  289. int n = pst.executeUpdate();
  290. if (n>0){
  291. cargar();
  292. JOptionPane.showMessageDialog(null, "Datos Modificados");
  293. }
  294. }catch (Exception e1){
  295.  
  296. JOptionPane.showMessageDialog(null, "ERROR" + e1.getMessage());
  297. }
  298. }
  299.  
  300.  
  301.  
  302. // INICIO DE METODO SALIR
  303. void salir() {
  304. System.exit(0);
  305. }
  306.  
  307. // FIN DE METODO SALIR
  308.  
  309. // INICIO METODO CARGAR DATOS BD A TABLA
  310.  
  311. void cargarfil(String valor) {
  312. try {
  313. String[] titulos = { "Codigo", "Nombre", "Edad", "Color", "Tipo" };
  314. String[] registros = new String[5];
  315.  
  316. String sql = "SELECT * FROM animales where nom_ani LIKE '%" + valor
  317. + "%'";
  318.  
  319. model = new DefaultTableModel(null, titulos);
  320.  
  321. conectar cc = new conectar();
  322. Connection cn = cc.conexion();
  323. Statement st = cn.createStatement();
  324. ResultSet rs = st.executeQuery(sql);
  325.  
  326. while (rs.next()) {
  327. registros[0] = rs.getString("cod_ani");
  328. registros[1] = rs.getString("nom_ani");
  329. registros[2] = rs.getString("eda_ani");
  330. registros[3] = rs.getString("col_ani");
  331. registros[4] = rs.getString("tip_ani");
  332. model.addRow(registros);
  333. }
  334. t_datos.setModel(model);
  335.  
  336. } catch (SQLException e1) {
  337. JOptionPane.showMessageDialog(null, "ERROR");
  338. }
  339. }
  340.  
  341. // FIN METODO CARGAR
  342.  
  343. void cargar() {
  344. try {
  345. String[] titulos = { "Codigo", "Nombre", "Edad", "Color", "Tipo" };
  346. String[] registros = new String[5];
  347.  
  348. String sql = "SELECT * FROM animales";
  349.  
  350. model = new DefaultTableModel(null, titulos);
  351.  
  352. conectar cc = new conectar();
  353. Connection cn = cc.conexion();
  354. Statement st = cn.createStatement();
  355. ResultSet rs = st.executeQuery(sql);
  356.  
  357. while (rs.next()) {
  358. registros[0] = rs.getString("cod_ani");
  359. registros[1] = rs.getString("nom_ani");
  360. registros[2] = rs.getString("eda_ani");
  361. registros[3] = rs.getString("col_ani");
  362. registros[4] = rs.getString("tip_ani");
  363. model.addRow(registros);
  364. }
  365. t_datos.setModel(model);
  366.  
  367. } catch (SQLException e1) {
  368. JOptionPane.showMessageDialog(null, "ERROR");
  369. }
  370. }
  371.  
  372. // FIN METODO CARGAR
  373.  
  374.  
  375. // DEJAMOS VISIBLE EL FRAME
  376. public static void main(String[] args) {
  377. ing_ani frame = new ing_ani();
  378. frame.setVisible(true);
  379.  
  380. }
  381. }
  382.  
  383. [ / code]
6  Programación / Java / Re: AYUDA SOBRE CODIGO en: 16 Noviembre 2013, 16:07 pm
GRACIAS  :-\ :-\
7  Programación / Java / AYUDA SOBRE CODIGO en: 15 Noviembre 2013, 03:44 am
 :-(

Estimados primero que todo muchas gracias, ahora bien, tengo un problema cuando trato de cargar un JTABLE CON LOS DATOS de una Base de datos  en MYSQL, se supone que con el boton consultar deberia mostrar los resultados, pero mi tabla aparece en blanco.


les pido su ayuda...

ESTA ES LA CLASE ing_clie


Código
  1. package formularios;
  2.  
  3.  
  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6. import javax.swing.table.DefaultTableModel;
  7. import javax.swing.JLabel;
  8. import javax.swing.JOptionPane;
  9. import javax.swing.JTextField;
  10. import javax.swing.JButton;
  11.  
  12. import java.awt.event.ActionListener;
  13. import java.awt.event.ActionEvent;
  14. import java.sql.*;
  15. import javax.swing.JTable;
  16.  
  17. public class ing_cli extends JFrame {
  18.  
  19. private JPanel contentPane;
  20. private JTextField t_nom;
  21. private JTextField t_ape;
  22. private JTextField t_ciu;
  23. private JTextField t_tel;
  24.  
  25. private JTable t_datos;
  26.  
  27.  
  28. // DECLARAMOS Y DAMOS ACCIONES
  29.  
  30. public ing_cli() {
  31.  
  32. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  33. setBounds(100, 100, 563, 533);
  34. contentPane = new JPanel();
  35. setContentPane(contentPane);
  36. contentPane.setLayout(null);
  37.  
  38. JLabel lblNombre = new JLabel("Nombre");
  39. lblNombre.setBounds(42, 46, 66, 14);
  40. contentPane.add(lblNombre);
  41.  
  42. JLabel lblIngresoClientes = new JLabel("Ingreso Clientes");
  43. lblIngresoClientes.setBounds(227, 11, 116, 14);
  44. contentPane.add(lblIngresoClientes);
  45.  
  46. JLabel lblApellido = new JLabel("Apellido");
  47. lblApellido.setBounds(42, 89, 66, 14);
  48. contentPane.add(lblApellido);
  49.  
  50. JLabel lblCiudad = new JLabel("Ciudad");
  51. lblCiudad.setBounds(42, 129, 66, 14);
  52. contentPane.add(lblCiudad);
  53.  
  54. JLabel lblTelefono = new JLabel("Telefono");
  55. lblTelefono.setBounds(42, 169, 66, 14);
  56. contentPane.add(lblTelefono);
  57.  
  58. t_nom = new JTextField();
  59. t_nom.setBounds(157, 43, 294, 20);
  60. contentPane.add(t_nom);
  61. t_nom.setColumns(10);
  62.  
  63. t_ape = new JTextField();
  64. t_ape.setBounds(157, 86, 294, 20);
  65. contentPane.add(t_ape);
  66. t_ape.setColumns(10);
  67.  
  68. t_ciu = new JTextField();
  69. t_ciu.setBounds(157, 126, 294, 20);
  70. contentPane.add(t_ciu);
  71. t_ciu.setColumns(10);
  72.  
  73. t_tel = new JTextField();
  74. t_tel.setBounds(157, 166, 294, 20);
  75. contentPane.add(t_tel);
  76. t_tel.setColumns(10);
  77.  
  78. // BOTON NUEVO
  79. JButton btnNuevo = new JButton("Nuevo");
  80. btnNuevo.addActionListener(new ActionListener() {
  81. public void actionPerformed(ActionEvent arg0) {
  82. limpiar();
  83. }
  84. });
  85. btnNuevo.setBounds(29, 211, 89, 23);
  86. contentPane.add(btnNuevo);
  87. // TERMINO BOTON NUEVO
  88.  
  89. // BOTON GRABAR
  90. JButton btnGrabar = new JButton("Grabar");
  91. btnGrabar.addActionListener(new ActionListener() {
  92. public void actionPerformed(ActionEvent e) {
  93. try{ conectar cc = new conectar ();
  94. Connection cn = cc.conexion();
  95. String nom, ape, ciu, tel;
  96. String sql="";
  97. nom = t_nom.getText();
  98. ape = t_ape.getText();
  99. ciu = t_ciu.getText();
  100. tel = t_tel.getText();
  101. sql="INSERT INTO clientes (nom_cli, ape_cli, ciu_cli, tel_cli) VALUES (?,?,?,?)";
  102.  
  103. PreparedStatement pst = cn.prepareStatement (sql);
  104. pst.setString(1,nom);
  105. pst.setString(2,ape);
  106. pst.setString(3,ciu);
  107. pst.setString(4,tel);
  108. int n = pst.executeUpdate();
  109. if (n>0){
  110. JOptionPane.showMessageDialog(null, "Registrado Grabado con exito");
  111. limpiar();
  112. }
  113.  
  114. } catch (SQLException e1) {
  115. JOptionPane.showMessageDialog(null, "ERROR");
  116. }
  117. }
  118. });
  119. btnGrabar.setBounds(128, 211, 89, 23);
  120. contentPane.add(btnGrabar);
  121. /// TERMINO BOTON GRABAR
  122.  
  123. // INICIO BOTON CONSULTAR
  124. JButton btnConsultar = new JButton("Consultar");
  125. btnConsultar.addActionListener(new ActionListener() {
  126. public void actionPerformed(ActionEvent e) {
  127. cargar();
  128. }
  129. });
  130. btnConsultar.setBounds(227, 211, 89, 23);
  131. contentPane.add(btnConsultar);
  132. // TERMINO DE BOTON CONSULTAR
  133.  
  134. // INICIO BOTON MODIFICAR
  135.  
  136. JButton btnModificar = new JButton("Modificar");
  137. btnModificar.setBounds(326, 211, 89, 23);
  138. contentPane.add(btnModificar);
  139. // TERMINO BOTON MODIFICAR
  140.  
  141. // INICIO BOTON SALIR
  142. JButton btnSalir = new JButton("Salir");
  143. btnSalir.setBounds(425, 211, 89, 23);
  144. contentPane.add(btnSalir);
  145. // TERMINO BOTON SALIR
  146.  
  147. // CREACION DE TABLA
  148. t_datos = new JTable();
  149. t_datos.setBounds(42, 247, 459, 224);
  150. contentPane.add(t_datos);
  151. // TERMINO TABLA
  152.  
  153. }
  154.  
  155. // INICIO METODO LIMPIAR
  156. void limpiar(){
  157. t_nom.setText("");
  158. t_ape.setText("");
  159. t_ciu.setText("");
  160. t_tel.setText("");
  161. }
  162.  
  163. // FIN METODO LIMPIAR
  164.  
  165. // INICIO METODO CARGAR DATOS BD A TABLA
  166. void cargar(){
  167. try{
  168. String [] titulos={"Codigo", "Nombre", "Apellido", "Ciudad", "Telefono"};
  169. String [] registros=new String[5];
  170.  
  171. String sql= "SELECT * FROM clientes";
  172.  
  173. model = new DefaultTableModel(null, titulos);
  174.  
  175. conectar cc=new conectar();
  176. Connection cn =cc.conexion();
  177. Statement st = cn.createStatement ();
  178. ResultSet rs = st.executeQuery(sql);
  179.  
  180. while(rs.next()){
  181. registros[0]=rs.getString("cod_cli");
  182. registros[1]=rs.getString("nom_cli");
  183. registros[2]=rs.getString("ape_cli");
  184. registros[3]=rs.getString("ciu_cli");
  185. registros[4]=rs.getString("tel_cli");
  186. model.addRow(registros);
  187.  
  188.  
  189. }
  190. } catch (SQLException e1) {
  191. JOptionPane.showMessageDialog(null, "ERROR");
  192. }
  193. }
  194.  
  195. // FIN METODO CARGAR
  196.  
  197. // DEJAMOS VISIBLE EL FRAME
  198. public static void main(String[] args) {
  199. ing_cli frame = new ing_cli();
  200. frame.setVisible(true);
  201. }
  202.  
  203. }[ / code]



ESTA ES LA CLASE conectar:

Código
  1. package formularios;
  2.  
  3. import java.sql.*;
  4. import javax.swing.*;
  5.  
  6. public class conectar {
  7. Connection conect = null;
  8.   public Connection conexion()
  9.    {
  10.      try {
  11.  
  12.           //Cargamos el Driver MySQL
  13.           Class.forName("org.gjt.mm.mysql.Driver");
  14.           conect = DriverManager.getConnection("jdbc:mysql://localhost:3306/bd","root","");
  15.           JOptionPane.showMessageDialog(null, "estás conectado");
  16.  
  17.        } catch (Exception e) {
  18.            JOptionPane.showMessageDialog(null,"Error "+e);
  19.        }
  20.        return conect;
  21.  
  22. }}[code==java]
  23.  
  24. NECESITAN EL SQL??
  25. muchas gracias y disculpen las molestias.
  26.  
  27.  
[/code]
8  Programación / Java / Re: Consulta sobre código en: 29 Octubre 2013, 03:02 am
gracias amigo
9  Programación / Java / Re: Consulta sobre código en: 29 Octubre 2013, 02:44 am
AMIGO ME RECOMIENDA ALGUN LIBRO PARA PRINCIPIANTES C;
10  Programación / Java / Re: Consulta sobre código en: 29 Octubre 2013, 02:23 am
Eres un genio, como hiciste eso, yo que estuve bastante tiempo trtando de hacerlo, mi codigo es gigante comparado al tuyo, mil gracias, investigare el resto,  ;)
Páginas: [1] 2
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines