-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstart.java
More file actions
60 lines (55 loc) · 2.41 KB
/
Copy pathstart.java
File metadata and controls
60 lines (55 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.sql.*;
class Start
{
public static void main(String args[])
{
try
{
// step1 load the driver class
Class.forName("com.mysql.jdbc.Driver");
// step2 create the connection object
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/db?characterEncoding=latin1&useConfigs=maxPerformance", "scott", "tiger");
// step3 create the statement object
Statement stmt = con.createStatement();
PreparedStatement ps = null;
// step4 execute query
String s = "create table stockings( pid integer primary key"
+", product varchar(20), price integer, qty integer)";
ps = con.prepareStatement(s);
ps.execute();
s = "CREATE TABLE ORDERS (Oid integer PRIMARY KEY, Prodid"
+ " integer, qty integer, dateofclosing date)";
ps = con.prepareStatement(s);
ps.execute();
s = "create table Customers( Cid integer primary key"
+", CName varchar(20), phoneNo integer, Locality varchar(20))";
ps = con.prepareStatement(s);
ps.execute();
s = "insert into stockings values(121,'cold coffee',88,10)";
ps = con.prepareStatement(s);
ps.execute();
s = "insert into stockings values(122,'doughnuts',120,20)";
ps = con.prepareStatement(s);
ps.execute();
//stmt.executeQuery("insert into orders values(1,121,5,to_date('28-02-2022','DD-MM-YYYY'))");
//stmt.executeQuery("insert into orders values(2,122,13,to_date('28-02-2022','DD-MM-YYYY'))");
ResultSet rsSt = stmt.executeQuery("select * from stockings");
//ResultSet rsOr = stmt.executeQuery("select * from orders");
while (rsSt.next())
{System.out.println(rsSt.getInt(1) + " " + rsSt.getString(2) + " \tRs." + rsSt.getInt(3)+" \tx "+rsSt.getInt(4));}
s = "drop table orders";
/* ps = con.prepareStatement(s);
boolean result = ps.execute();
s = "drop table stockings";
ps = con.prepareStatement(s);
result = ps.execute();*/
// step5 close the connection object
con.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}