OCP - 4
NIO.2, JDBC
NIO.2, JDBC
Kartei Details
Karten | 66 |
---|---|
Sprache | English |
Kategorie | Informatik |
Stufe | Andere |
Erstellt / Aktualisiert | 30.04.2019 / 08.01.2020 |
Weblink |
https://card2brain.ch/box/20190430_ocp_4
|
Einbinden |
<iframe src="https://card2brain.ch/box/20190430_ocp_4/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>
|
Lernkarteien erstellen oder kopieren
Mit einem Upgrade kannst du unlimitiert Lernkarteien erstellen oder kopieren und viele Zusatzfunktionen mehr nutzen.
Melde dich an, um alle Karten zu sehen.
How can jdbc determine which driver to use?
A driver does advertise itself via a file called java.sql.Driver in the META-INF/services directory. Otherwise, the Class.forName("fqn.of.driver") has to be used.
How can you obtain a JDBC statement?
connection.createStatement()
connection.createStatement(ResultSet.Type_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)
What is the difference between the different ResultSet Types?
- TYPE_FORWARD_ONLY: Usually sufficient, only next() is availbale.The view is static (new updates are not visible)
- TYPE_SCROLL_INSENSITIVE Can scroll in any directoy,.The view is static (new updates are not visible)
- TYPE_SCROLL_SENSITIVE: Can scroll in any directoy, the view is not static: new updates are visible. Not supported by most dirvers
What is the difference of the different result set concurrency modes?
- CONCUR_READ_ONLY
- CONCUR_UPDATABLE - not universally supported.
What is the difference between statment.execute() , statment.executeUpdate() and statement.executeQuery()?
- statment.executeUpdate() - intended for DELETE, INSERT, UPDATE: Returns the number of affected rows
- statement.executeQuery() - intended for SELECT: Returns a Result Set
- statment.execute(): Generic: Returns true for a SELECT, otherwise false
What is the result of this code:
int result = stmt.executeUpdate("select * from animal");
An Exception is thrown: A resut was returned when none was expected
How does a Result set work?
- It is a Cursor, meaning it points to a row (or a virtual row above/below the table)
- navigate using next() and - if supported - previous(), absolte(), relative(), ...
- multiple get___ Methods return the value of the column index/name in the current row
What has to be considered when working with column indices in Result Sets?
The columns are counted starting with 1 rather than 0
What happens if you don't call and check rs.next() before calling rs.get___(..)
The get___(..) method might throw an SQLException
How can you convert a java.sql.Date, java.sql.Time and java.sql.TimeStamp Object into a LocalDate/LocalTime, LocalDateTime?
Using the convenient Time.toLocalTime(), TimeStamp.toLocalDateTime(), Date.toLocalDate methods
Why do the return type of first()/last() and beforeFirst()/afterLast() differ?
The beforeFirst and afterLast do always work, making a return type redundant.
Where does the cursor point to when calling rs.absolute(0)
Same as rs.beforeFirst()
Where does the cursor point to when calling rs.absolute(-1)
To the last entyr in the table
What implicit rules corresponding to a JDBC connection, Statement and ResultSet exist?
- Closing a Connection also closes the Statement and ResultSet
- Closing a Statement also closes the ResultSet
- JDBC automatically clsoes a ResultSet when you run another SQL statement from the same Statement
What is the difference between a paht.toRealPaht() and paht.toAbsolutePath()?
toAbsolutePaht does not operate on the fs ("theory") while toRealPath will resolve symbolic links . toRealPaht will throw an exceptiom if the file does not exist
What is the goal of the NIO.2 API?
To provide a replacement for the java.io.FIle class
What is the java.nio.file.Path class for?
It represents a path on the storage system to a file or directory. Its the direct replacement for the java.io.File class.
It can represent a File, Directory or Symlink
How can you construct a Path object?
- Using the Paths factory class, eg. Phats.get(...)
- by prividing one or multiple Strings
- by providing a URI
- Using a FileSystem instance, eg. Filesystem.getPath(...)
- From a Legacy File instance: aFIle.toPath()
Note that Path is an Interface!
Does it matter which path separator you use when constructing a Path?
Usually not, as most JVMs support both forward and backward slashes.
How can you simply construct a phat without using a path separator
Using the Path.get(String, String...) varargs overload
What happens when constructing a path with a URI to a relative path?
Paths.get(new URI("file://relative/path"));
An IllegalArgumentException is thrown
What has to be considered when using the URI constructor?
It throws a checked URISyntaxException
How can you convert a Path to a URI
Using the toUri() method
What is the difference between FileSystems.getDefault().getPath(...) and Paths.get()?
Its identical, the Paths API is just convenience
When shoud the FileSystem class be used over the Paths class to construct paths?
When working with remote file systems, eg. FTP
Is it necessary for a file to exist when working with a Path object?
For most operations: no. There are a hand ful of methods - such as Path.toRealPath() that require the file to exist and throw an Exception if the file is not available
What are the mothods Path.getNameCount and Path.getName for?
They can be used to access Fragments of a path
Paths.of("/foo/baa/x").getNameCount() // 3
Paths.of("/foo/baa/x").getName(1) // Paths.of("baa")
What does Path.getParent(".") return?
null
What does Path.getParent("/") return?
null
What does Path.getParent("/foo") return?
Paths.get("/")
-
- 1 / 66
-