File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .sql .*;
2+ public class demo {
3+ public static void main (String [] args ) {
4+
5+ try {
6+ Connection con =DriverManager .getConnection ("jdbc:mysql://localhost:3306/" ,"root" ,"SanthoshPassword" );
7+ Statement stmt =con .createStatement ();
8+ stmt .executeUpdate ("CREATE DATABASE company" );
9+ stmt .executeUpdate ("""
10+ CREATE TABLE company.employee
11+ (
12+ Id int NOT NULL UNIQUE,
13+ Name char(50) NOT NULL
14+ );
15+
16+ """ );
17+ System .out .println ("Database created successfully" );
18+ stmt .executeUpdate ("INSERT INTO company.employee VALUES(101,'ram')" );
19+ stmt .executeUpdate ("INSERT INTO company.employee VALUES(102,'raaam')" );
20+ ResultSet rs =stmt .executeQuery ("SELECT * FROM company.employee" );
21+ while (rs .next ())
22+ {
23+ System .out .println ("ID: " +rs .getInt (1 )+" NAME: " +rs .getString (2 ));
24+ }
25+ stmt .executeUpdate (" UPDATE company.employee SET Name='raaaaaaam' WHERE Name='ram' " );
26+ ResultSet r =stmt .executeQuery ("SELECT * FROM company.employee" );
27+ System .out .println ("After editing: " );
28+ while (r .next ())
29+ {
30+ System .out .println ("ID: " +r .getInt (1 )+" NAME: " +r .getString (2 ));
31+ }
32+ stmt .executeUpdate ("DELETE FROM company.employee WHERE Id=101" );
33+ ResultSet s =stmt .executeQuery ("SELECT * FROM company.employee" );
34+ System .out .println ("After deleting: " );
35+ while (s .next ())
36+ {
37+ System .out .println ("ID: " +s .getInt (1 )+" NAME: " +s .getString (2 ));
38+ }
39+
40+
41+ }
42+ catch (Exception e ) {
43+ System .out .println (e );
44+ }
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments