How to create a simple Add Data to Database mysql in Netbeans with Source Code

Leave a Comment
How to import the system with clean and build in Netbeans…


Open Project or Control+Shift+O


Find the Coffe the the file name of the System then click open project


In the project the are 2 types of package the connect for connection and the oop_student for the designing.
After that click the dropdown package in oop_student then double click the your_name.java the click the design



Then Double click the Add data to view the Code…

// this code contain the ADD DATA  Button
    try {

            String sql= "Insert into c_info(idno,name,middlename,lastname)values(?,?,?,?)";
            PreparedStatement pst = cn.prepareStatement(sql);
             pst.setString(1, idno.getText());
             pst.setString(2, name.getText());
             pst.setString(3, middlename.getText());
             pst.setString(4, lastname.getText());
            
             pst.execute();
            JOptionPane.showMessageDialog(null, "SAVED!");
           
            idno.setText(null);
            name.setText(null);
            middlename.setText(null);
            lastname.setText(null);

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "NOT SAVED!");
        }


For connection you can view the conectar.java
// this is the code of the conectar.java to connect to database
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 to import the database please make sure you open or run the wamp server or xamp server
… How to import Database?
Click wamp server or xamp in wamp server make sure the w logo is green for xamp server make sure the apache and my sql are running or start.
Click the google chrome or Mozilla
Write in your browser the
Localhost/phpmyadmin then enter.


The database overview in wamp server is this:


After you click the create button the database is already created and after the process click the import button in the top then choose file find the oop student folder open the folder database the click the info.sql the GO…
 

Now you can run the simple system  left click of your_name.java and click Run File of Shift+F6


This is the output of the system



Source Code: Click Me!!
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment