Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
Lab 5 Old Version
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
com_1028_labs
Lab 5 Old Version
Commits
1d057156
Commit
1d057156
authored
1 year ago
by
joeappleton18
Browse files
Options
Downloads
Patches
Plain Diff
finished exercise-2-2-solution
parent
cc353308
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/com/yatl/Main.java
+17
-22
17 additions, 22 deletions
src/main/java/com/yatl/Main.java
src/main/java/com/yatl/model/Todo.java
+0
-1
0 additions, 1 deletion
src/main/java/com/yatl/model/Todo.java
with
17 additions
and
23 deletions
src/main/java/com/yatl/Main.java
+
17
−
22
View file @
1d057156
package
com.yatl
;
package
com.yatl
;
import
java.net.URL
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
...
@@ -7,44 +7,39 @@ import java.sql.Statement;
...
@@ -7,44 +7,39 @@ import java.sql.Statement;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
com.yatl.util.Database
;
import
com.yatl.model.Todo
;
import
com.yatl.model.Todo
;
import
com.yatl.util.Database
;
public
class
Main
{
public
class
Main
{
static
List
<
Todo
>
todos
=
new
ArrayList
<>();
static
List
<
Todo
>
todos
=
new
ArrayList
<>();
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
URL
resourceFolderUrl
=
Main
.
class
.
getClassLoader
().
getResource
(
""
);
String
databasePath
=
"src/main/resources/database.db"
;
String
databasePath
=
resourceFolderUrl
.
getPath
()
+
"database.db"
;
String
url
=
"jdbc:sqlite:"
+
databasePath
;
String
url
=
"jdbc:sqlite:"
+
databasePath
;
Database
database
=
Database
.
getInstance
(
url
);
Database
db
=
Database
.
getInstance
(
url
);
Connection
conn
=
database
.
getConnection
();
Connection
conn
=
db
.
getConnection
();
Statement
stmt
;
Statement
stmt
;
try
{
try
{
stmt
=
conn
.
createStatement
();
stmt
=
conn
.
createStatement
();
ResultSet
rs
=
stmt
.
executeQuery
(
"SELECT * FROM todos"
);
ResultSet
rs
=
stmt
.
executeQuery
(
"SELECT * FROM todos"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
todos
.
add
(
new
Todo
(
rs
.
getInt
(
"id"
),
rs
.
getString
(
"title"
),
rs
.
getBoolean
(
"completed"
)));
todos
.
add
(
new
Todo
(
rs
.
getInt
(
"id"
),
rs
.
getString
(
"title"
),
rs
.
getBoolean
(
"completed"
)));
}
}
for
(
Todo
todo:
todos
)
{
for
(
Todo
todo
:
todos
)
{
System
.
out
.
println
(
todo
.
toString
());
System
.
out
.
println
(
todo
.
toString
());
}
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
// TODO Auto-generated catch block
// TODO Auto-generated catch block
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/yatl/model/Todo.java
+
0
−
1
View file @
1d057156
...
@@ -9,7 +9,6 @@ public class Todo {
...
@@ -9,7 +9,6 @@ public class Todo {
public
Todo
(
int
id
,
String
title
,
boolean
done
)
{
public
Todo
(
int
id
,
String
title
,
boolean
done
)
{
super
();
this
.
id
=
id
;
this
.
id
=
id
;
this
.
title
=
title
;
this
.
title
=
title
;
this
.
done
=
done
;
this
.
done
=
done
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment