Java Database Interview Questions II
- How do you handle your own transaction ? - Connection Object has a method called setAutocommit(Boolean istrue)
- Default is true. Set the Parameter to false , and begin your transaction - What is the normal procedure followed by a java client to access the db.? - The database connection is created in 3 steps:
- Find a proper database URL
- Load the database driver
- Ask the Java DriverManager class to open a connection to your database
In java code, the steps are realized in code as follows:
- Create a properly formatted JDBR URL for your database. (See FAQ on JDBC URL for more information). A JDBC URL has the form
jdbc:someSubProtocol://myDatabaseServer/theDatabaseName - Class.forName(”my.database.driver”);
- Connection conn = DriverManager.getConnection(”a.JDBC.URL”, “databaseLogin”,”databasePassword”);
- What is a data source? - A DataSource class brings another level of abstraction than directly using a connection object. Data source can be referenced by JNDI. Data Source may point to RDBMS, file System , any DBMS etc.
- What are collection pools? What are the advantages? - A connection pool is a cache of database connections that is maintained in memory, so that the connections may be reused
- How do you get Column names only for a table (SQL Server)? Write the Query. -
select name from syscolumns where id=(select id from sysobjects where name='user_hdr') order by colid --user_hdr is the table name























