package com.samplejdbc;
import java.sql.*;
public class exp11 {

	public static void main(String[] args) throws Exception {
	Class.forName("com.mysql.cj.jdbc.Driver");
	Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sample","root","ravis#2004");
	PreparedStatement ps=con.prepareStatement("insert into mytable(ID,NAME) values(?,?)");
	ps.setInt(1, 16);
	ps.setString(2,"Swami");
	int i=ps.executeUpdate();
	System.out.println("data inserted");
	PreparedStatement ps1=con.prepareStatement("select * from mytable");
	ResultSet rs=ps1.executeQuery();
	
	while(rs.next()) {
		System.out.println("uname"+rs.getString(1));
		System.out.println("pwd"+rs.getString(2));
	}
	con.close();
	ps.close();
	}

}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: