Posts

Upload File

  < h3 > File Upload: </ h3 > Select a file to upload: < br /> < form action = "/Dmart/Product" method = "post" enctype = "multipart/form-data" > < input type = "file" name = "Image" size = "50" /> < br /> < input type = "submit" value = "Upload File" /> </ form > //========================================================= import java.io.File; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.MultipartConfig; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.Part; @WebServlet("/Product") @MultipartConfig public class Product extends HttpServlet { public Product() { super(); // T...

MDI Open JFreame

    // TODO add your handling code here:         jInternalFrame1.setSize(400, 300);         jInternalFrame1.setLocation(0, 0);         jDesktopPane1.add(jInternalFrame1);         try {             jInternalFrame1.setMaximum(true);         } catch (PropertyVetoException ex) {             Logger.getLogger(DashBoard.class.getName()).log(Level.SEVERE, null, ex);         }      jInternalFrame1.setVisible(true);

DataBase Part1

  import java.sql.Connection;    import java.sql.ResultSet;   import java.sql.DriverManager;  import java.sql.SQLException;       public class DataBase {          private static final String URL = "jdbc:mysql://localhost:3306/testdb";     private static final String USER = "root";     private static final String PASSWORD = "Sabir123@";     private static final String DBDRIVER = "com.mysql.cj.jdbc.Driver";          java.sql.Statement stmt=null;     Connection con;          public void OpenConnection(){                 try{          Class.forName(DBDRIVER); con = DriverManager.getConnection(URL,USER,PASSWORD);          System.out.print("Connection Success");         }catch(Exception e){          ...

USE In another JFrame

     DataBase db=new DataBase();          public NewJFrame() {         initComponents();        // db.OpenConnection(); //       db.Insertrecord("Sabir", "BCA II", "1001", "223333"); //       db.Insertrecord("Prem", "BCA III", "101", "333"); //       db.Insertrecord("Tejas", "BCA I", "1091", "444"); //       db.Insertrecord("Atul", "BCA II", "1021", "555");       // db.Updaterecord("1", "Sabir", "BCA III", "1011", "223333");      ///db.DeleteRecord("1");                ResultSet rs=  db.ReadStudent();          try{           while(rs.next()){               System.out.println("Name:"+rs.getString("Name"));           }         ...

CRUD Opration

 /*  * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license  * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template  */   import java.sql.Connection;    import java.sql.ResultSet;   import java.sql.DriverManager;  import java.sql.SQLException;       public class DataBase {          private static final String URL = "jdbc:mysql://localhost:3306/testdb";     private static final String USER = "root";     private static final String PASSWORD = "Sabir123@";     private static final String DBDRIVER = "com.mysql.cj.jdbc.Driver";          java.sql.Statement stmt=null;     Connection con;          public void OpenConnection(){                 try{          Class.forName(DBDR...

🛢️ MySQL Connection & CRUD Operations in Java

🛢️ MySQL Connection & CRUD Operations in Java In this guide, you will learn how to connect Java applications to a MySQL database and perform basic CRUD (Create, Read, Update, Delete) operations using JDBC (Java Database Connectivity). 🔌 1. Setting up MySQL Connector First, download the MySQL Connector/J (JDBC driver) and add the JAR file to your project’s build path or dependencies. 📡 2. Connecting to MySQL Database import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class DBConnection { private static final String URL = "jdbc:mysql://localhost:3306/testdb"; private static final String USER = "root"; private static final String PASSWORD = "your_password"; public static Connection getConnection() { try { return DriverManager.getConnection(URL, USER, PASSWORD); } catch (SQLException e) { System.out.println("Connection Failed!"); e.printStackTrace(); ...

📁 Java File Handling

  📘 1. Introduction to File Handling in Java File handling in Java allows programmers to store, retrieve, and manipulate data in files stored on the disk. This is achieved using classes from the java.io and java.nio packages. 📁 2. File Class Overview Java provides a File class in the java.io package to represent the pathnames of files and directories. 📘 1. Creating a File import java.io.File; import java.io.IOException; public class CreateFile { public static void main(String[] args) { try { File file = new File("example.txt"); if (file.createNewFile()) { System.out.println("File created: " + file.getName()); } else { System.out.println("File already exists."); } } catch (IOException e) { System.out.println("An error occurred."); e.printStackTrace(); } } } ✍️ 2. Writing to a File import java....