Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GoikLectures
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Goik Martin
GoikLectures
Commits
50b0fcec
Commit
50b0fcec
authored
5 years ago
by
Goik Martin
Browse files
Options
Downloads
Patches
Plain Diff
Removin solution from Exam (previous commit)
parent
8a842c9e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Klausuren/Sda1/2018Winter/Exam/Schema/schema.sql
+33
-11
33 additions, 11 deletions
Klausuren/Sda1/2018Winter/Exam/Schema/schema.sql
Klausuren/Sda1/2018Winter/Exam/src/main/java/de/hdm_stuttgart/mi/sda1/Book2Rdbms.java
+39
-46
39 additions, 46 deletions
...am/src/main/java/de/hdm_stuttgart/mi/sda1/Book2Rdbms.java
with
72 additions
and
57 deletions
Klausuren/Sda1/2018Winter/Exam/Schema/schema.sql
+
33
−
11
View file @
50b0fcec
...
...
@@ -5,19 +5,41 @@ DROP TABLE IF EXISTS Section;
-- Read the exercise's documentation and add your schema here. You may
-- re-use subsequent INSERT statements or adapt them to your schema.
--
CREATE TABLE
...
CREATE
TABLE
Section
(
INSERT
INTO
Section
VALUES
(
'categories'
,
'XML Document categories'
,
NULL
,
'new'
,
1
);
INSERT
INTO
Section
VALUES
(
'wellFormed'
,
'Well-formed documents'
,
'categories'
,
NULL
,
2
);
id
CHAR
(
255
)
NOT
NULL
PRIMARY
KEY
,
title
VARCHAR
(
255
)
NOT
NULL
,
parent
CHAR
(
255
)
NULL
REFERENCES
Section
,
revisionflag
CHAR
(
7
)
NULL
,
orderNo
INT
NOT
NULL
GENERATED
ALWAYS
AS
IDENTITY
UNIQUE
,
CHECK
(
revisionflag
IN
(
'new'
,
'changed'
,
'deleted'
))
);
INSERT
INTO
Para
VALUES
(
'categories'
,
'Documents belonging to this category do not adhere to any schema.'
,
'changed'
,
3
);
CREATE
TABLE
Para
(
parent
CHAR
(
255
)
NOT
NULL
REFERENCES
Section
,
para
TEXT
,
revisionflag
CHAR
(
7
)
NULL
,
orderNo
INT
NOT
NULL
GENERATED
ALWAYS
AS
IDENTITY
UNIQUE
,
CHECK
(
revisionflag
IN
(
'new'
,
'changed'
,
'deleted'
))
);
INSERT
INTO
Section
(
id
,
title
,
parent
,
revisionflag
)
VALUES
(
'categories'
,
'XML Document categories'
,
NULL
,
'new'
);
INSERT
INTO
Section
(
id
,
title
,
parent
,
revisionflag
)
VALUES
(
'wellFormed'
,
'Well-formed documents'
,
'categories'
,
NULL
);
INSERT
INTO
Section
VALUES
(
'valid'
,
'Valid documents'
,
'categories'
,
NULL
,
4
);
INSERT
INTO
Para
VALUES
(
'valid'
,
'Valid documents require a schema.'
,
'changed'
,
5
);
INSERT
INTO
Para
VALUES
(
'valid'
,
'Common standards are DTD, XML Schema and Relax-NG.'
,
NULL
,
6
);
INSERT
INTO
Para
(
parent
,
para
,
revisionflag
)
VALUES
(
'categories'
,
'Documents belonging to this category do not adhere to any schema.'
,
'changed'
);
INSERT
INTO
Section
VALUES
(
'api'
,
'Available APIs'
,
NULL
,
'deleted'
,
7
);
INSERT
INTO
Para
VALUES
(
'api'
,
'We introduce SAX and DOM here.'
,
NULL
,
8
);
INSERT
INTO
Para
VALUES
(
'api'
,
'Some APIs offer multiple language bindings.'
,
NULL
,
9
);
\ No newline at end of file
INSERT
INTO
Section
(
id
,
title
,
parent
,
revisionflag
)
VALUES
(
'valid'
,
'Valid documents'
,
'categories'
,
NULL
);
INSERT
INTO
Para
(
parent
,
para
,
revisionflag
)
VALUES
(
'valid'
,
'Valid documents require a schema.'
,
'changed'
);
INSERT
INTO
Para
(
parent
,
para
,
revisionflag
)
VALUES
(
'valid'
,
'Common standards are DTD, XML Schema and Relax-NG.'
,
NULL
);
INSERT
INTO
Section
(
id
,
title
,
parent
,
revisionflag
)
VALUES
(
'api'
,
'Available APIs'
,
NULL
,
'deleted'
);
INSERT
INTO
Para
(
parent
,
para
,
revisionflag
)
VALUES
(
'api'
,
'We introduce SAX and DOM here.'
,
NULL
);
INSERT
INTO
Para
(
parent
,
para
,
revisionflag
)
VALUES
(
'api'
,
'Some APIs offer multiple language bindings.'
,
NULL
);
SELECT
*
FROM
Section
;
SELECT
*
FROM
Para
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Klausuren/Sda1/2018Winter/Exam/src/main/java/de/hdm_stuttgart/mi/sda1/Book2Rdbms.java
+
39
−
46
View file @
50b0fcec
package
de.hdm_stuttgart.mi.sda1
;
import
org.jdom2.*
;
import
org.jdom2.filter.ElementFilter
;
import
org.jdom2.input.SAXBuilder
;
import
org.jdom2.xpath.XPathExpression
;
import
org.jdom2.xpath.XPathFactory
;
import
java.io.File
;
import
java.io.IOException
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
public
class
Book2Rdbms
{
public
class
Book2Rdbms
implements
AutoCloseable
{
private
Connection
conn
;
private
Document
doc
;
private
Connection
conn
;
public
Book2Rdbms
()
{
try
{
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost/hdm"
,
"hdmuser"
,
"XYZ"
);
}
catch
(
SQLException
e
)
{
System
.
err
.
println
(
"Unable to establish connection: "
+
e
);
System
.
exit
(
1
);
}
private
Element
book
;
final
SAXBuilder
builder
=
new
SAXBuilder
();
try
{
doc
=
builder
.
build
(
new
File
(
"Schema/sampledata.xml"
));
//getClass().getClassLoader().getResource("Schema/sampledata.xml"));
}
catch
(
JDOMException
e
)
{
e
.
printStackTrace
();
System
.
err
.
println
(
"Unable to parse input: "
+
e
);
System
.
exit
(
1
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
System
.
err
.
println
(
"Unable to read input: "
+
e
);
System
.
exit
(
1
);
}
}
public
void
execute
()
{
final
XPathExpression
<
Element
>
xpathSearchPara
=
XPathFactory
.
instance
().
compile
(
"//para"
,
new
ElementFilter
(),
null
,
Namespace
.
getNamespace
(
null
));
public
Book2Rdbms
(
)
{
try
{
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost/hdm"
,
"hdmuser"
,
"XYZ"
);
System
.
out
.
println
(
"Java stream:"
);
xpathSearchPara
.
evaluate
(
doc
).
stream
().
map
(
Element:
:
getText
).
forEach
(
System
.
out
::
println
);
System
.
out
.
println
(
"\nSimple loop:"
);
for
(
final
Element
e:
xpathSearchPara
.
evaluate
(
doc
))
{
System
.
out
.
println
(
e
.
getText
());
}
}
catch
(
SQLException
e
)
{
System
.
err
.
println
(
"Unable to establish connection: "
+
e
);
System
.
exit
(
1
);
}
final
SAXBuilder
builder
=
new
SAXBuilder
();
try
{
book
=
builder
.
build
(
new
File
(
"Schema/sampledata.xml"
)).
getRootElement
();
}
catch
(
JDOMException
e
)
{
e
.
printStackTrace
();
System
.
err
.
println
(
"Unable to parse input: "
+
e
);
System
.
exit
(
1
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
System
.
err
.
println
(
"Unable to read input: "
+
e
);
System
.
exit
(
1
);
}
}
public
void
execute
()
{
System
.
out
.
println
(
book
.
getChild
(
"title"
));
}
@Override
public
void
close
()
{
try
{
conn
.
close
();
}
catch
(
final
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
}
\ No newline at end of file
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