A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

JDBC Program for Insert Records In Table Using Mysql

//step1. import sql packages import java.sql.*; public class InsertRecordsInTable { public static void main(String args[]){ try { //step2. Load Driver class or to install a driver Class.forName("com.mysql.jdbc.Driver"); //step3. Create a connection Object Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/programmingshifts", "root", "pass"); //step4. Create Statement object to execute sql queries Statement st=con.createStatement(); //Step5 Execute query int i= st.executeUpdate("insert into student values(10,'navneet','delhi')"); if(i>0) { System.out.println("Registration successful..."); } st.close(); con.close(); } catch (ClassNotFoundException ex) { System.out.println("Driver not found"); } catch (SQLException ex) { System.out.println("Database Connection not found."); } } }