-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent.java
More file actions
71 lines (42 loc) · 1.41 KB
/
Copy pathstudent.java
File metadata and controls
71 lines (42 loc) · 1.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
61
62
63
64
65
66
67
68
69
70
71
package jdbconnectivity;
import java.sql.*;
import java.util.Scanner;
import java. sql.DriverManager;
public class student {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("enter the name:");
String name=input.nextLine();
System.out.println("enter course");
String course=input.nextLine();
System.out.println("enter student id");
int id=input.nextInt();
System.out.println("enter phone");
int phone=input.nextInt();
try {
Connection con =DriverManager.getConnection("jdbc:mysql://localhost/comrade","root","");
Statement stat=con.createStatement();
String sql="insert into details(name,stud_id,course,phone) values(?,?,?,?)";
PreparedStatement t=con.prepareStatement(sql);
t.setString(1, name);
t.setInt(2, id);
t.setString(3, course);
t.setInt(4, phone);
t.executeUpdate();
System.out.println("inserting");
System.out.println("INSERTED!!!");
ResultSet rs=stat.executeQuery(sql);
while(rs.next()) {
String n=rs.getString("name");
//String name=rs.getString("first_name");
//String course=rs.getString("email");
//---------------------------------------
System.out.println(n);
//System.out.println(course);
//System.out.println(index);
}
}catch(Exception ex){
System.out.println(ex);
}
}
}