java 2 3
fdsa
fdsa
-
- 1 / 496
-
Lernkarten
What is a resource leak and how to prevent this?
When the resource is never closed -> close it
Why is reading of files w.o. cheging its size a problem?
The files could be very large -> check the size first to prevent memory issues
What is a inclusion attack?
F.e. billion laughs attack or zip bomb. A file which could expand more and more to become really big
What is the problem with ovwerflowing numbers? How to prevent?
Unpredictable outcomes -> input validation
What is "wasting data structures"?
F.e. the possibility to create a class with a hashCode which always return 42 and put it to a hashmap or the possibility to create very large datastructures
Does ArrayList have a copy method?
no
What does ArrayList.clone() return?
Object -> be aware to cast it
Where is the clone() Method declared?
In the objectclass
Whats the difference between a black and a whitelist?
Whitelist compares against allowed values (could also throw an exception if not valid)
What does readObject() return?
Object
What does readResolve() return?
Object
Where are the 5 key interfaces for JDBC declared?
In the JDK
Where do we get the concrete classes for JDBC interfaces from?
From the JDBC driver
Which interfaces are implemented within the driver JAR?
Driver, Connection, PreparedStatement, CallableStatement, ResultSet
Do we use the concrete JDBC classes in code?
No, only the interfaces
Whats neccessary in a jdbc url? Which colons?
prefix jdbc + subprotocol for the db + name/address of the database, separated by :
jdbc:postgresql://localhost/zoo
Is it possible to create a jdbc-connection via constructor
No, use DataManager.getConnection for the exam, in real life: DataSource
Which exception is thrown by DriverManager.getConnection?
SqlException (check in examquestions if it is thrown)
What are the benefits of a PreparedStatement?
- Performance
- Security
- Readability
- Future use
Is it possible to create a preparedStatement without providing a query as parameter?
No, this will not compile:
var ps = conn.prepareStatement()
How to get the returned Value of ps.execute() ?
Check first if it returned something (returned value will be boolean indicating if returnvalue or updatecount), then get the resultset via ps.getResultset if it is true or ps.getUpdateCount if it is false
What happens with incompatible returntypes? (f.e. SELECT-query but executeUpdate() called)
Will throw a SQLException like: .executeUpdate cannot be called with a statement
What is the returntype and the returnvalues for select/[delete|insert|update] for ps.execute()
boolean, true for select, false for updates
What is the returntype and the returnvalues for select/[delete|insert|update] for ps.executeQuery()?
ResultSet, rows and columns returned for select
What is the returntype and the returnvalues for select/[delete|insert|update] for ps.executeUpdate?
int, number of rows added/changed/removed returned for updates
Where does the bindvariables within a preparedStatement start to count?
start with 1
What happens if not all bindVariables are set in a preparedStatement?
Code compiles but SQLException
What happens if to many bindVariables are provided for a prepared statement?
SQLException like "the number of values assigned is not the same as the number of specified or implied columns"
Can we use the same perparedStatement for multiple executeUpdates? Whats with the bindVariables?
Yes, the perparedStatement will remember the parameters that were already set if not changed
What does resultSet.next() do?
Sets the cursor to the next element, returns boolean indicating if it worked
Where does the counting stat within a resultSet?
at 1
What params does f.e. resultSet.getInt accept?
either 1/2/.. or the columnname
Is it neccessary to call rs.next() first?
Yes, if no result returned we have to break. Even with result we have to call it to set the cursor to the first element
What happens if we try to acces a column which doesn access in jdbc?
Throws a SQLException like: "Column 'bla' not found"
Which getMethods are provided by a resultSet?
- getBoolean
- getDouble
- getInt
- getLong
- getObject
- getString
What are the benefits of stored procedures?
redudes network roundtrips, allows expert to handle their part of code, ..
Whats the returntype of connection.perpareCall(sql)?
CallableStatement
How is the syntax to call a stored procedure?
call + proecdurename in braces, f.e.: {call read_e_names()}
Whats neccessary for passing IN parameters to stored procedures?
a ? to show that we have a parameter, f.e.: "{call read_names_by_letter(?)]"
How to set parameters in callableStatements?
Unlike preparedStatement htere are two ways, the parameter number or name:
cs.setString(1, "Z")
cs.setString("prefix", "Z")