-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectStudentRecords.java
More file actions
51 lines (40 loc) · 1.52 KB
/
SelectStudentRecords.java
File metadata and controls
51 lines (40 loc) · 1.52 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
package TeacherRegister;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class SelectStudentRecords {
private Connection connect() throws ClassNotFoundException {
// SQLite connection string
String url = "jdbc:sqlite:C://sqlite/SSSIT.db";
Connection conn = null;
try {
Class.forName("org.sqlite.JDBC");
conn = DriverManager.getConnection(url);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return conn;
}
public void selectAll() throws ClassNotFoundException{
String sql = "SELECT * FROM Marks";
try {
Connection conn = this.connect();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
// loop through the result set
while (rs.next()) {
System.out.println(rs.getInt("RollNo") + "\t" +
rs.getString("Name") + "\t" +
rs.getDouble("Marks"));
}
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
/**
* @param args the command line arguments
* @throws ClassNotFoundException
*/
}