You are on page 1of 6

Experiment no 18

import java.sql.*;

public class Database_2

public static void main(String args[])

String data="jdbc:mysql://localhost/VEDANT";

try

Class.forName("com.mysql.jdbc.Driver");

System.out.println("Driver Loaded");

Connection con=DriverManager.getConnection(data,"root","root");

System.out.println("Connection Establish...");

con.close();

Statement statement=con.createStatement();

statement.execute("create table employee(emp_id int,emp_name varchar(20))");

System.out.println("TABLE EMPLOYEE CREATED");

} catch (Exception e)

System.out.println(e);

}
Experiment 19
import java.sql.*;

public class Database_3

public static void main(String args[])

String data="jdbc:mysql://localhost/VEDANT";

try

Class.forName("com.mysql.jdbc.Driver");

System.out.println("Driver Loaded");

Connection con=DriverManager.getConnection(data,"root","root");

System.out.println("Connection Establish...");

PreparedStatement statement=con.prepareStatement("insert into student values(?,?,?);");

statement.setInt(1,38);

statement.setString(2,"vedant");

statement.setFloat(3,86f);

statement.executeUpdate();

System.out.println("Record inserted");

con.close();

} catch (Exception e)

{
System.out.println(e);

}
Expriment 20
import java.sql.*;

public class Database_4

public static void main(String args[])

String data="jdbc:mysql://localhost/VEDANT";

try

Class.forName("com.mysql.jdbc.Driver");

System.out.println("Driver Loaded");

Connection con=DriverManager.getConnection(data,"root","root");

System.out.println("Connection Establish...");

PreparedStatement statement=con.prepareStatement("update student set rollno=3 where


name='Abhishek';");

statement.executeUpdate();

System.out.println("Table updated");

Statement statement2=con.createStatement();

statement2.execute("update student set name='John' where name='Jack';");

System.out.println("TABLE updated");

statement2.execute("Delete from product where price>500 and id='p1234';");

System.out.println("Deleted record");

con.close();

catch (Exception e)
{

System.out.println(e);

You might also like