FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Lab-File-Programs/Q23_Retrieve_DB_data.java at main · sagargoswami2001/Java-Lab-File-Programs · GitHub
sagargoswami2001
/
Java-Lab-File-Programs
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
7
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Lab-File-Programs
/
Q23_Retrieve_DB_data.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
53 lines (44 loc) · 1.37 KB
Breadcrumbs
Java-Lab-File-Programs
/
Q23_Retrieve_DB_data.java
Copy path
File metadata and controls
53 lines (44 loc) · 1.37 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//Q23. WAP to retrieve data from database.
package
JAVA_Lab_File
;
import
java
.
sql
.
DriverManager
;
import
java
.
sql
.
Connection
;
import
java
.
sql
.
ResultSet
;
import
java
.
sql
.
SQLException
;
import
java
.
sql
.
Statement
;
public
class
Q23_Retrieve_DB_data
{
private
Connection
connect
() {
String
url
=
"jdbc:sqlite:Logins.Sqlite3"
;
Connection
conn
=
null
;
try
{
conn
=
DriverManager
.
getConnection
(
url
);
}
catch
(
SQLException
e
) {
System
.
out
.
println
(
e
.
getMessage
());
}
return
conn
;
}
public
void
selectAll
(){
String
sql
=
"SELECT * FROM Members"
;
try
{
Statement
stmt
;
try
(
Connection
conn
=
this
.
connect
()) {
stmt
=
conn
.
createStatement
();
}
ResultSet
rs
=
stmt
.
executeQuery
(
sql
);
// loop through the result set
while
(
rs
.
next
()) {
System
.
out
.
println
(
rs
.
getInt
(
"id"
) +
"
\t
"
+
rs
.
getString
(
"name"
) +
"
\t
"
+
rs
.
getDouble
(
"capacity"
));
}
}
catch
(
SQLException
e
) {
System
.
out
.
println
(
e
.
getMessage
());
}
}
/**
* @param args the command line arguments
*/
public
static
void
main
(
String
[]
args
) {
Q23_Retrieve_DB_data
app
=
new
Q23_Retrieve_DB_data
();
app
.
selectAll
();
}
}
Back
|
FazBrowse Home
|
New Git URL