DBA > Job Interview Questions > DERBY Java Database FAQs

How to Specify Attributes in a Properties Object

More DBA job interview questions and answers at http://dba.fyicenter.com/Interview-Questions/

(Continued from previous question...)

How to Specify Attributes in a Properties Object ?

Instead of specifying attributes on the connection URL, you can specify attributes as properties in a Properties object that you pass as a second argument to the DriverManager.getConnection method. For example, to set the user name and password:
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
Properties p = new Properties();
p.put("user", "sa");
p.put("password", "manager");
Connection conn = DriverManager.getConnection(
"jdbc:derby:mynewDB", p);

(Continued on next question...)

Other Job Interview Questions