-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.java
More file actions
31 lines (29 loc) · 1003 Bytes
/
Database.java
File metadata and controls
31 lines (29 loc) · 1003 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
import java.sql.*;
class Database{
public static void main(String... arg) throws Exception{
Class.forName("org.sqlite.JDBC");
Connection Conn = DriverManager.getConnection("jdbc:sqlite:C://MyJava//SQLite//university.db");
Statement STM = Conn.createStatement();
ResultSet Result = STM.executeQuery("select * from Student");
int RollNo;
String SName;
String City;
int DeptNo;
System.out.println("\n\n---------Student Data fetched from JDBC-----------");
while(Result.next()){
RollNo = Result.getInt("RollNo");
SName = Result.getString("SName");
City = Result.getString("City");
DeptNo = Result.getInt("DeptNo");
System.out.println(RollNo+" "+SName+" "+City+" "+DeptNo);
}
Result = STM.executeQuery("select * from Dept");
String DName;
System.out.println("\n\n----------Department Data fetched from JDBC-----------");
while(Result.next()){
DName = Result.getString("DName");
DeptNo = Result.getInt("DeptNo");
System.out.println(DName+" "+DeptNo);
}
}
}