-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjdbctest2.java
More file actions
70 lines (43 loc) Β· 1.75 KB
/
jdbctest2.java
File metadata and controls
70 lines (43 loc) Β· 1.75 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
61
62
63
64
65
66
67
68
69
70
import javax.naming.Name;
import java.sql.*;
import java.util.Scanner;
public class jdbctest2 {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.cj.jdbc.Driver");//Register
Connection co = DriverManager.getConnection("jdbc:mysql://localhost:3306/mrgreshsehrawat","root","");
// // (1.) inserting Data
// Scanner sc = new Scanner(System.in);
//
// String Name = "KrishnaRadhe";
// int Marks = 89;
// int RollNo = 64;
//
// String q = "insert into student value(?,?,?)";
// PreparedStatement ps = co.prepareStatement(q);
// ps.setInt(1,RollNo);
// ps.setInt(3,Marks);
// ps.setString(2,Name);
// ps.executeUpdate();
// (2.) Update Contant
// String e = "update student SET Name = ? where RollNo = ?";
// PreparedStatement ps = co.prepareStatement(e);
// ps.setInt(2,9);
// ps.setString(1,"Jalal");
// ps.executeUpdate();
//(3.) Delete Content
// String k = "delete from student where Marks = ?";
// PreparedStatement ps = co.prepareStatement(k);
// ps.setInt(1,95);
// ps.executeUpdate();
Statement stm = co.createStatement();
// (4.) Delete Content
// stm.execute("delete from student where RollNo = 24 ");
// (5.) Update Contant
// stm.executeUpdate("update student SET Name = 'Govind' where RollNo = 48");
ResultSet rst = stm.executeQuery("select * from student");
while (rst.next())
{
System.out.println(rst.getInt("RollNo") +" "+ rst.getString("Name") +" "+ rst.getInt("Marks"));
}
}
}