How to display data in database using java netbeans table source code.

Leave a Comment
Drag the Table from the Panel..

This is the Table left click under the table and change the variable name into table.


Left Click under the table and click the change Variable Name into table



Now Click the Source.


Paste this code:
public display_data_table() {
        initComponents();
        sss();
    }

    
     private void sss()
         {
             try
             {
                 String sql ="SELECT id as num,idno as PID,name as Name, middlename as Middlename, lastname as Lastname FROM c_info";
                    Statement st = cn.createStatement();
                    ResultSet rs = st.executeQuery(sql);
                table.setModel(net.proteanit.sql.DbUtils.resultSetToTableModel(rs)); 
             }catch(Exception e)
             {
                 JOptionPane.showMessageDialog(null,"NOT VIEW");
             }
         }



 






















At the buttom paste this code:
conectar cc= new conectar();
Connection cn = cc.conexion();

Create new java package and rename this as connect:

Left Click Connect click new – the click the java class  - name as conectar and paste this code and save:
package connect;

import java.sql.*;
import javax.swing.*;


public class conectar {
Connection conect = null;

   public Connection conexion()
    {
      try {
            
         
           Class.forName("com.mysql.jdbc.Driver");
           conect = DriverManager.getConnection("jdbc:mysql://localhost:3306/info","root","");
         
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null,"Error "+e);
        }
        return conect;
    
}

}


Now Click the Google Chrome or Mozilla or any other Internet Browser in your PC Please make sure you install the wamp or the xamp server and type this: localhost/phpmyadmin and go to SQL


After you click the SQL please type this code: create database info and click GO.




After you click the Go the database Create and paste this Code into the sql command:
CREATE TABLE IF NOT EXISTS `c_info` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `idno` varchar(255) DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `middlename` varchar(255) DEFAULT NULL,
  `lastname` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `c_info`
--

INSERT INTO `c_info` (`id`, `idno`, `name`, `middlename`, `lastname`) VALUES
(1, '45', 'sdad', 'sda', 'da'),
(2, '222', 'we', 'eww', 'w'),
(3, '111', 'ddas', 'dsadsad', 'asdsa'),
(4, '333', 'ffsd', 'fdsfsd', 'fsdfs');





After the procedure the info database have a data so you can now go Back to Netbeans and Run the System left click the display_data_table and click the run file or shift f6:


And the Output of the System is this:




If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment