1. FULL CRUD OPERATIONS ON MVC()
MODEL
		using System;
		using System.Collections.Generic;
		using System.Linq;
		using System.Web;
		using System.Web.Mvc;
		using System.ComponentModel;
		using System.ComponentModel.DataAnnotations;
		
		
	   public class StudentModel
       {

         [Display(Name = "Id")]
         public int StudentId { get; set; }


         [Display(Name = "Student Name")]
         [Required(ErrorMessage="Please Enter student name")]
         [StringLength(50,ErrorMessage="Maximum 30 characters allowed")]
         [RegularExpression(@"^[a-zA-Z]+[ a-zA-Z-_]*$", ErrorMessage = "Use Characters only")]
         public string StudentName { get; set; }



         [Display(Name="Gender")]
         [Required(ErrorMessage="Please select Gender")]
         public string Gender { get; set; }


         [Display(Name="Mobile No")]
         [Required(ErrorMessage="Please enter Mobile Number")]
         [StringLength(10, ErrorMessage="Maxlenght 10")]
         [RegularExpression("([1-9][0-9]*)", ErrorMessage = "Only Numbers allowed")]
         public string MobileNo { get; set; }


         [Display(Name="Email-ID")]
         [Required(ErrorMessage="Please enter Emailid")]
         [StringLength(30,ErrorMessage="Maxlength 50 characters")]
         [RegularExpression("^[a-zA-Z0-9_\\.-]+@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$", ErrorMessage = "E-mail is not valid")]
         public string EmailId { get; set; }


         [Display(Name="Class")]
         [Required(ErrorMessage="Please select Your Class")]
         public string ClassName {get; set;}


         [Display(Name="IsActive")]
         public bool IsActive { get; set; }

       }
		
		
ESTABLISH A CONNECTION STRING
		
		  < connectionStrings >
       < add name="schoolConnectionString" connectionString="Data Source=DESKTOP-37O63IN;Initial Catalog=school;Integrated Security=True" providerName="System.Data.SqlClient" / >
  < / connectionStrings >
         
	   
		
CREATE CODE COMPLETE :-
		  using System.Web.Mvc;
          using SchoolProject_Best.Models;
		
		
		public class StudentController : Controller
        {

        StudentDataContext db = new StudentDataContext();


        [HttpGet]
        public ActionResult Create()
        {

            
            return View();


        }


        [HttpPost]
        public ActionResult Create(StudentModel model)
        {

            try
            {

                if (ModelState.IsValid)
                {

                    // Code Execute when Everything is going right
                    
                    StudentRegistration studentRegistration = new StudentRegistration();
                    studentRegistration.StudentName= model.StudentName;
                    studentRegistration.Gender = model.Gender;
                    studentRegistration.MobileNo = model.MobileNo;
                    studentRegistration.EmailId = model.EmailId;
                    studentRegistration.ClassName = model.ClassName;
                    studentRegistration.IsActive = model.IsActive;
                    db.StudentRegistrations.InsertOnSubmit(studentRegistration);
                    // yaha TempData isliye liya hai kyonki value Ek action se dusre action par jaa rahai hai
                    // Matlab Yeh ki hamm Create action se Index action par message Bhej rahe hai
                    // iss bat ko dhyan rakho
                    db.SubmitChanges();
                    TempData["DataSaved"] = "Saved Successfully";
                    return RedirectToAction("Index");
                }
                else
                {

                    return View("Create",model);

                }

            }
            catch
            {

                ViewBag.ErrorMessage = "Something Went Wrong, Try again";
                return View("Create", model);

            }

        }
     }
		
		
		
		@model SchoolProject_Best.Models.StudentModel

@{
    ViewBag.Title = "Create";
}

@ViewBag.ErrorMessage


@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

    

        

            
              
@Html.TextBoxFor(model => model.StudentName, new { @class="form-control", placeholder="Enter student name" , autocomplete = "off"}) @Html.ValidationMessageFor(model => model.StudentName)
Gender : Male @Html.RadioButtonFor(model => model.Gender,"Male") Female @Html.RadioButtonFor(model => model.Gender, "Female") @Html.ValidationMessageFor(model => model.Gender)
@Html.TextBoxFor(model => model.MobileNo,new { @class="form-control", placeholder="Enter mobile no" , autocomplete = "off"}) @Html.ValidationMessageFor(model => model.MobileNo)
@Html.TextBoxFor(model => model.EmailId, new { @class="form-control", placeholder="Enter emailid" , autocomplete = "off"}) @Html.ValidationMessageFor(model => model.EmailId)
@Html.DropDownListFor(m => m.ClassName, new List { new SelectListItem() {Text = "Class X", Value="Class X"}, new SelectListItem() {Text = "Class XI", Value="Class XI"}, new SelectListItem() {Text = "Class XII", Value="Class XII"} }, "-- Select class -- ",new {@class="form-control"}) @Html.ValidationMessageFor(model => model.ClassName)
@Html.EditorFor(model => model.IsActive, new { @class="form-control"}) @Html.ValidationMessageFor(model => model.IsActive)
@Html.ActionLink("Back to List", "Index")
} @section Scripts { @Scripts.Render("~/bundles/jqueryval") }
INDEX PAGE CODE OR PAGE LOAD CODE
		 [HttpGet]
        public ActionResult Index()
        {
		
		 try
            {
                
                var students = db.StudentRegistrations.Select(sr => new StudentModel
                    {
                       
                        
                        StudentId = sr.StudentId,
                        StudentName = sr.StudentName,
                        Gender = sr.Gender,
                        MobileNo = sr.MobileNo,
                        EmailId = sr.EmailId,
                        ClassName = sr.ClassName,
                        IsActive = (bool)sr.IsActive
                        

                    }).ToList();
                return View(students);
            }
            catch
            {


                ViewBag.ErrorMessage = "Something Went Wrong";
                return View();


            }
		
		}
		
		
		
		
		
		@model IEnumerable< SchoolProject_Best.Models.StudentModel >

		@{
			ViewBag.Title = "Index";
		}
		
		
		
		< table >
        < tr >
     	< th >
		@Html.DisplayNameFor(model => model.StudentId)
	    < /th >
         < /tr >
       < th >
            @Html.DisplayNameFor(model => model.StudentName)
        < /th >
        < th >
            @Html.DisplayNameFor(model => model.Gender)
        < /th >
        < th >
            @Html.DisplayNameFor(model => model.MobileNo)
        < /th >
        < th >
            @Html.DisplayNameFor(model => model.EmailId)
        < /th >
        < th >
            @Html.DisplayNameFor(model => model.ClassName)
        < /th >
        < th >
            @Html.DisplayNameFor(model => model.IsActive)
        < /th >

        @if (Model != null && Model.Count() > 0)
       {

        foreach (var item in Model) {

    < tr >
        < td >
            @Html.DisplayFor(modelItem => item.StudentId)
        < /td >
        < td >
            @Html.DisplayFor(modelItem => item.StudentName)
        < /td >
        < td >
             @Html.DisplayFor(modelItem => item.Gender)
        < /td >
        < td >
            @Html.DisplayFor(modelItem => item.MobileNo)
        < /td >
        < td >
            @Html.DisplayFor(modelItem => item.EmailId)
        < /td >
        < td >
            @Html.DisplayFor(modelItem => item.ClassName)
        < /td >
        < td >
            @Html.DisplayFor(modelItem => item.IsActive)
        < /td >
        < td >
            @Html.ActionLink("Edit", "Edit", new { id=item.StudentId }) |
            @Html.ActionLink("Details", "Details", new { id=item.StudentId }) |
            @Html.ActionLink("Delete", "Delete", new {  id=item.StudentId })
        < /td >
    < /tr >
}    


      

  
}
    else
    {
    
       
     < p >No Record Found< /p >
    
     
}

	 
	 
	 
	 
	 

        < /table >
		
		
		
		
		
		
		
EDIT CODE
		[HttpGet]
        public ActionResult Edit(int id)
        {

            try
            {

               
                var StudentEntity = db.StudentRegistrations.Where(sr => sr.StudentId == id).SingleOrDefault();
                if (StudentEntity != null)
                {
                    StudentModel StudModel = new StudentModel();
                    StudModel.StudentName = StudentEntity.StudentName;
                    StudModel.Gender = StudentEntity.Gender;
                    StudModel.MobileNo = StudentEntity.MobileNo;
                    StudModel.EmailId = StudentEntity.EmailId;
                    StudModel.ClassName = StudentEntity.ClassName;
                    StudModel.IsActive = (bool)StudentEntity.IsActive;
                    return View(StudModel);
                }
                else
                {

                    ViewBag.ErrorMessage = "ID Not exist";
                    return View();

                }

                

            }
            catch
            {

                ViewBag.ErrorMessage = "Something Went Wrong";
                return View();


            }




        }
		
		
		
		
		        [HttpPost]
        public ActionResult Edit(int id , StudentModel model)
        {

            try
            {
                 // Case 1 : Check the model is valid or not
                if(ModelState.IsValid)
                {
                    // Found that model is valid and all validations are work properly
                      var StudentEntity = db.StudentRegistrations.SingleOrDefault(sr => sr.StudentId == id);
                      if (StudentEntity != null)
                      {

                          StudentEntity.StudentName = model.StudentName;
                          StudentEntity.Gender = model.Gender;
                          StudentEntity.MobileNo = model.MobileNo;
                          StudentEntity.EmailId = model.EmailId;
                          StudentEntity.ClassName = model.ClassName;
                          StudentEntity.IsActive = model.IsActive;
                          db.SubmitChanges();
                          return RedirectToAction("Index");



                      }
                      else
                      {

                          // Found the record is not exist
                          ViewBag.ErrorMessage = "No record Exist";
                          return View(model);

                      }



                }
                else
                {
                    // If server not responding than the exception will be handled
                    return View(model);


                }



            }
            catch
            {

                // DNS errror handling
                ViewBag.ErrorMessage = "Something went wrong , Please Try again";
                return View();

            }

        }
		
		
		
		
		@model SchoolProject_Best.Models.StudentModel

@{
    ViewBag.Title = "Edit";
}

Edit

@using (Html.BeginForm()) { @Html.ValidationSummary(true)
@Html.LabelFor(model => model.StudentName)
@Html.EditorFor(model => model.StudentName) @Html.ValidationMessageFor(model => model.StudentName)
@Html.LabelFor(model => model.Gender)
Gender : Male @Html.RadioButtonFor(model => model.Gender, "Male") Female @Html.RadioButtonFor(model => model.Gender, "Female") @Html.ValidationMessageFor(model => model.Gender)
@Html.LabelFor(model => model.MobileNo)
@Html.EditorFor(model => model.MobileNo) @Html.ValidationMessageFor(model => model.MobileNo)
@Html.LabelFor(model => model.EmailId)
@Html.EditorFor(model => model.EmailId) @Html.ValidationMessageFor(model => model.EmailId)
@Html.LabelFor(model => model.ClassName)
@Html.DropDownListFor(model => model.ClassName, new List{ new SelectListItem() {Text="Class X", Value= "Class X"}, new SelectListItem() {Text="Class XI", Value= "Class XI"}, new SelectListItem() {Text="Class XII", Value= "Class XII"} }, "Please select", new {@class="form-control"}) @*@Html.EditorFor(model => model.ClassName)*@ @Html.ValidationMessageFor(model => model.ClassName)
@Html.LabelFor(model => model.IsActive)
@Html.EditorFor(model => model.IsActive) @Html.ValidationMessageFor(model => model.IsActive)

}
@Html.ActionLink("Back to List", "Index")
@section Scripts { @Scripts.Render("~/bundles/jqueryval") }
DELETE CODE
		[HttpGet]  
        public ActionResult Delete(int id)
        {

            //StudentModel studmodel = db.StudentRegistrations.Where(sr => sr.StudentId == id).Select(val => new StudentModel
            //{

            //    StudentId = val.StudentId,
            //    StudentName = val.StudentName,
            //    Gender = val.Gender,
            //    MobileNo = val.MobileNo,
            //    EmailId = val.EmailId,
            //    ClassName = val.ClassName
            //}).SingleOrDefault();

            //return View(studmodel);


            try
            {

                var StudentEntity = db.StudentRegistrations.Where(sr => sr.StudentId == id).SingleOrDefault();
                if (StudentEntity != null)
                {
                    StudentModel StudModel = new StudentModel();
                    StudModel.StudentName = StudentEntity.StudentName;
                    StudModel.Gender = StudentEntity.Gender;
                    StudModel.MobileNo = StudentEntity.MobileNo;
                    StudModel.EmailId = StudentEntity.EmailId;
                    StudModel.ClassName = StudentEntity.ClassName;
                    StudModel.IsActive = (bool)StudentEntity.IsActive;
                    return View(StudModel);
                }
                else
                {

                    ViewBag.ErrorMessage = "Record Not exist";
                    return View();

                }

               


            }
            catch
            {

                ViewBag.ErrorMessage = "Something Went Wrong";
                return View();


            }


        }
		
		
		
		        [HttpPost]
        public ActionResult Delete(int id, StudentModel model)
        {
            try
            {

                var StudentEntity = db.StudentRegistrations.Where(sr => sr.StudentId == id).SingleOrDefault();
                if (StudentEntity != null)
                {

                    db.StudentRegistrations.DeleteOnSubmit(StudentEntity);
                    db.SubmitChanges();
                    return RedirectToAction("Index");

                }
                else
                {

                    ViewBag.ErrorMessage = "OOps Record Not exist";
                    return View();

                }



            }
            catch
            {

               
                ViewBag.ErrorMessage = "Something went wrong";
                return View("Index");

            }

        }
		
		
		@model SchoolProject_Best.Models.StudentModel

@{
    ViewBag.Title = "Delete";
}

Delete

Are you sure you want to delete this?

@Html.DisplayNameFor(model => model.StudentId)
@Html.DisplayFor(model => model.StudentId)
@Html.DisplayNameFor(model => model.StudentName)
@Html.DisplayFor(model => model.StudentName)
@Html.DisplayNameFor(model => model.Gender)
@Html.DisplayFor(model => model.Gender)
@Html.DisplayNameFor(model => model.MobileNo)
@Html.DisplayFor(model => model.MobileNo)
@Html.DisplayNameFor(model => model.EmailId)
@Html.DisplayFor(model => model.EmailId)
@Html.DisplayNameFor(model => model.ClassName)
@Html.DisplayFor(model => model.ClassName)
@Html.DisplayNameFor(model => model.IsActive)
@Html.DisplayFor(model => model.IsActive)
@using (Html.BeginForm()) {

| @Html.ActionLink("Back to List", "Index")

}

2. Important Codes(Part II)
To fill combobox through loop:-
for(int i=1;i<=10;i++)
{
cmb.addItem(i);
}
To print record in netbeans:-


    
    private void BtnPrintActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // Here we use Table component to print data
        MessageFormat header = new MessageFormat("Patient Information");
        MessageFormat Footer = new MessageFormat("Page{0,number,integer}");
        
        try
        {
            
            Mytable.print(JTable.PrintMode.NORMAL,header,Footer);
            
        }
        catch(Exception ex)
        {
            JOptionPane.showMessageDialog(null, ex);
        }
        
    }                                     

		
To set selectedindexchanged property of combobox:-
if(jComboBox1.getSelectedIndex()<=0)
{
JOptionPane.showMessageDialog(this, "Select Item first");
}
How to fill string in combbox:-
String[] a = new String[2];
a[0]="January";
a[1]="February";
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(a));
To check whether textbox is empty or not:-
  String a = jTextField1.getText();
if(a.isEmpty()==true)
{
JOptionPane.showMessageDialog(this, "Please fill value");
}
To Delete Record on button click as shown below:-


Right Click on button and make this event


int MySlectedRow = jTable1.getSelectedRow();
        if(MySlectedRow==-1)
        {
            JOptionPane.showMessageDialog(this, "Please Select At least one Row");
        }
        else
        {         
            int response = JOptionPane.showConfirmDialog(null, "Do you want to continue","Confirm",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);
            if(response==JOptionPane.YES_OPTION)
                {
                  int row = jTable1.getSelectedRow();

                              int row = jTable1.getSelectedRow();
                  // 0 means first column 
                  // 1 means second column
                  // 2 means third column 
                  int ID = Integer.parseInt(jTable1.getValueAt(row, 0).toString());
                  
                  jTextField2.setText(jTable1.getValueAt(row, 1).toString());
                                    
            // Now write your delete code here and pass the id to delete the object
               
                }
          
        }

		

3. Important Codes(Part III)
To enters only numbers in textbox:-
import java.awt.event.KeyEvent;
private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) {                                       
        char c = evt.getKeyChar();
if ( ((c < '0') || (c > '9')) && (c != KeyEvent.VK_BACK_SPACE))
{ jTextField1.setEditable(false); } else { jTextField1.setEditable(true); } }
Print Record Using Professional way
  


Step 1:- Add these library
import javax.swing.JFrame;
import java.awt.print.PrinterException;
import java.util.logging.Level;
import java.util.logging.Logger;

Step 2: 
private void btnAddRecordActionPerformed(java.awt.event.ActionEvent evt) {                   

                          
        
        txtReceipt.append("\t\t\t Jayshree Periwal International School" + "\n\n"+
                "\n ##############################\n"+"\n\n"+ 
                "First Name \t\t\t" + txtfirstname.getText()+ "\n\n"+
                "Last Name:\t\t\t" + txtlastname.getText()+ "\n\n"+
                "Mobile Number:\t\t\t" + txtmobileno.getText()+ "\n\n"+
                "Refrence Number:\t\t" + txtrefreence.getText()+ "\n\n"
                 );
        
    }  

Step 3 : 
private void BtnPrintActionPerformed(java.awt.event.ActionEvent evt) {                             

            
        try {
            

            txtReceipt.print();
        } catch (PrinterException ex) {
            Logger.getLogger(Temp.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    } 





		
Validation of remove duplicate entry:-
  
	import java.sql.SQLException;



try
           {
           Statement stmk =(Statement)con.createStatement();

           

           String sqlk ;

   sqlk = "insert into take(mobileno,username)values('"+ username +"','"+ ddk +"')";

   stmk.executeUpdate(sqlk);
           
           }
           catch(SQLException e)
           {
               
               
               
System.out.println("Message = " + e.getMessage());

               
                   JOptionPane.showMessageDialog(this, e.getMessage());
                 
           }
		
To show tables and schema in MYSQL:-
  
	    1.  show tables;
2. desc student; or Describe student;
To create code on menu item:-
  
	
    private void AddPatinetActionPerformed(java.awt.event.ActionEvent evt) {                                           
        this.setVisible(false);
        new Dashboard().setVisible(true);
    }        
		
To set maxlength of textbox:-
		You have to create this code at keypressed event
private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) {
if(jTextField1.getText().length()>=5)
{
jTextField1.setText(jTextField1.getText().substring(0, 4));
}
To set Return Type function in netbeans:-
Step 1 :- First create class in the project


Step 2 :- Than make a function like this

Step 3:- Now call the function on button click like this
    private void btnCalculateReturnActionPerformed(java.awt.event.ActionEvent evt) {                                                   
             
        NewClass ClassObject = new NewClass();
        int kuldd = ClassObject.SumTwoNumbers(5, 10);
        JOptionPane.showMessageDialog(this, kuldd);
               
    }                                                  

	
		

4. Important Codes(Part IV)
To set current system date and time in netbeans:-
You have to add this files in header first

import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
private void formWindowOpened(java.awt.event.WindowEvent evt) { // TODO add your handling code here: SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy"); Date date = new Date(); jLabel2.setText(formatter.format(date)); Calendar cal = Calendar.getInstance(); cal.getTime(); SimpleDateFormat sdfd24hour = new SimpleDateFormat("HH:mm:ss"); SimpleDateFormat sdfd12hour = new SimpleDateFormat("hh:mm a"); jLabel3.setText(sdfd12hour.format(cal.getTime())); jLabel4.setText(sdfd24hour.format(cal.getTime())); }
To set break point in netbeans:-
         Step1: first of all pehle ki tarah breakpoint lagao ASP.net ki tarah
Step 2: then keyboar Ctrl+Shift+f5 dabao, page run ho jaiyega

Step 3: phir button pe click kare jaha aapne brk point lagaya tha

Step 3:- thne f8 dabate jao or value check hoti jaigi

(In case if it is not working with f8 then use f7)

(Note For checking loop USe F8)
Refresh Code:-

String studid = txtstudname.getText();
        String studname = txtfathername.getText();
        
        
      try
        {
            Class.forName("java.sql.DriverManager");
            Connection conk = (Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/school","root","kulbhushan");
            Statement stmk =(Statement)conk.createStatement();
            
            DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
            
            String myquery;
            myquery = "select * from studinfo";
            
            ResultSet rs = stmk.executeQuery(myquery);
            
                     int rows = model.getRowCount(); 
            
for(int i = rows - 1; i >=0; i--)
{
   model.removeRow(i); 
}


 while(rs.next())
            {
                
String teachername = rs.getString("mobileno");
                String contactno = rs.getString("username");
                
                model.addRow(new Object[]{teachername,contactno});
            }


            stmk.close();
            conk.close();
            
            
        }
        catch(Exception ex)
                {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
        
        		
		
Delete Code in netbeans:-

        int response;
        if(txtteachername.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(this, "Please Select Record First!!");
        }
        else
        {

            try
            {
                Class.forName("java.sql.DriverManager");
                Connection conk = (Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/school","root","kullu");
                Statement stmk =(Statement)conk.createStatement();

                response = JOptionPane.showConfirmDialog(null, "Do you want to continue","Confirm",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);
                if(response==JOptionPane.YES_OPTION)

                //JOptionPane.showMessageDialog(this, "yes right");

                {

                    String DeleteQuery;
                 DeleteQuery = "delete from staff where teacherid=" + Mainteacherid + "";

                    stmk.executeUpdate(DeleteQuery);
                    JOptionPane.showMessageDialog(this, "Deleted Successfully");
                    txtteachername.setText("");
                    txtcontactno.setText("");
                    txtsalary.setText("");

                    DefaultTableModel model = (DefaultTableModel)jTable1.getModel();

                    String myquery;
                    myquery = "select * from staff";

                    ResultSet rs = stmk.executeQuery(myquery);
                    while(rs.next())

                    {
                        String teacherid = rs.getString("teacherid");
                        String teachername = rs.getString("teachername");
                        String contactno = rs.getString("contactno");
                        String teachingclass = rs.getString("teachingclass");
                        String salary = rs.getString("salary");
                        String Qualification = rs.getString("qualification");
                        String Experience = rs.getString("experience");
                        String gender = rs.getString("gender");
                        model.addRow(new Object[]{teacherid,teachername,gender,contactno,teachingclass,salary,Qualification,Experience});

                    }

                }

                stmk.close();
                conk.close();

            }
            catch(Exception ex)
            {
                JOptionPane.showMessageDialog(this, ex.getMessage());
            }

        }

		
		
Use of Tree Component in netbeans:-
	If u want to use tree component than use it Event- Tree_selection and write
your code according ur requirement.

5. Important Codes(Part IV)
Database connectivity in netbeans:-
  import javax.swing.JOptionPane;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.sql.Driver;
import javax.swing.table.DefaultTableModel;

private void btnsaveActionPerformed(java.awt.event.ActionEvent evt) {
String teachername = txtteachername.getText();
String contactno = txtcontactno.getText();
String salary = txtsalary.getText();
String teachingclass = (String)cmbteachingclass.getSelectedItem();
String Qualification = (String)cmbqualification.getSelectedItem();
String Experience = (String)cmbexperience.getSelectedItem();
if(teachername.isEmpty())
{
JOptionPane.showMessageDialog(this, "Please Teacher Name First");
}
else if(contactno.isEmpty())
{
JOptionPane.showMessageDialog(this, "Please fill Contact No");
}
else if(salary.isEmpty())
{
JOptionPane.showMessageDialog(this, "Please fill Salary");
}
else
{
String Mygender="";
if(rdmale.isSelected())
{
Mygender=rdmale.getText();
}
else
{
Mygender=rdfemale.getText();
}


try
{
Class.forName("java.sql.DriverManager");
Connection conk = (Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/school","root",
"password");
Statement stmk =(Statement)conk.createStatement();
String sqlk ;
sqlk = "insert into staff(teachername,gender,contactno,teachingclass,salary,qualification,experience)
values('"+ teachername +"','"+ Mygender + "','" + contactno + "',
'" + teachingclass +"','"+ salary +"','" + Qualification +"','"+ Experience+"')";
stmk.executeUpdate(sqlk);
JOptionPane.showMessageDialog(this, "Saved Successfully");
txtteachername.setText("");
txtcontactno.setText("");

DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
String myquery; myquery = "select * from staff";
ResultSet rs = stmk.executeQuery(myquery);
while(rs.next())
{
int Teacherid;
Teacherid = Integer.parseInt(rs.getString("teacherid"));
teachername = rs.getString("teachername");
contactno = rs.getString("contactno");
Mygender= rs.getString("gender");
teachingclass = rs.getString("teachingclass");
salary = rs.getString("salary");
Qualification = rs.getString("Qualification");
Experience = rs.getString("Experience");
//model.fireTableDataChanged();
model.addRow(new Object[]{Teacherid,teachername,Mygender,contactno,teachingclass,salary,
Qualification,Experience});
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(this, ex.getMessage());
}
}

6. Important Codes(Part VI)
Database Connectivity in netbeans(Xampp):-
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import java.sql.*;
import java.util.*;



String username = txtusername.getText();
String password = txtpassword.getText();
try
{
String url="jdbc:mysql://localhost:3306/school";
Properties prop=new Properties();
prop.setProperty("user","root");
prop.setProperty("password","");


Driver d = new com.mysql.jdbc.Driver();


Connection con = d.connect(url,prop);
if(con==null)
{
System.out.println("connection failed");
return;
}
else
{
Statement stmk =(Statement)con.createStatement();


String myquery;
myquery = "select * from stud";


ResultSet rs = stmk.executeQuery(myquery);


while(rs.next())
{

String MYusername = rs.getString("studname");
String MYPassword = rs.getString("fname");


if(username.equals(MYusername) && password.equals(MYPassword))
{
this.setVisible(false);
new staff().setVisible(true);
}
else
{
JOptionPane.showMessageDialog(this, "Incorrect Username Or Password");
}
}
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(this, ex.getMessage());
}

7. Important Codes(Part VII)
When Xampp Gives Problem after Installation:-
		HOW TO START:-

Open the browser and just type localhost:80

or

localhost:80/phpmyadmin


NOTE:- Some times we see that after installing it not work it gives the error
404 NOt Found. Than we have to change some settings.

Step 1 :- U see that if folders save on C: Drive under the name
Xampp. after that go to the folder apache, than go to
the folder conf than go the file httpd.conf.


Step 2:- Just open the httpd.conf file with notepad and search
with the keyword Listen u will notice that there
is a wriiten a port no 80 in front of listen,
now just replace 80 to 81 or whatever u want to give the
port no.

Step 3:- Now open the browser and type:- localhost:81
OR
localhost:81/phpmyadmin

Free Web Hosting
Free Web Hosting