Back To Java JDBC Database Connectivity Index
//program to connect to a mysql database and insert records in the table package javajdbc; import java.sql.*; public class javajdbc2 { public static void main(String[] args) { // TODO code application logic here try { String driverName = "com.mysql.jdbc.Driver"; Class.forName(driverName); String url ="jdbc:mysql://127.0.0.1:3306/students"; Statement stmt; int rs; Connection con =DriverManager.getConnection(url,"root", ""); // Create a connection to the database stmt = con.createStatement(); rs = stmt.executeUpdate("insert into student values(11,'abcdef',11,78)"); } catch(Exception e) { System.out.println(e.toString()); } } }