-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent.java
More file actions
37 lines (28 loc) · 909 Bytes
/
Copy pathstudent.java
File metadata and controls
37 lines (28 loc) · 909 Bytes
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
package assignment1;
import java.sql.*;
public class student {
public static void main(String[] args) throws SQLException {
// Connect to database
Connection conn = null;
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db1?" +
"user=root&password&useSSL=false&serverTimezone=GMT");
// Create a statement to retrieve objects
Statement s = conn.createStatement();
// Retrieve results from the table
ResultSet rs = s.executeQuery ("Select * from Student");
// Print columns headers
ResultSetMetaData rsmd =rs.getMetaData();
int i =rsmd.getColumnCount( );
for(int j=1; j<=i; j++) {
System.out.print(rsmd.getColumnName(j)+"\t");
System.out.print(" ");
}
// Print records
while(rs.next( ) ) {
for(int j=1; j<=i; j++)
{
System.out.print ( rs.getString( j)+"\t");
}
}
}
}