aspose file tools*
The moose likes JDBC and the fly likes How do i avoid this exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How do i avoid this exception " Watch "How do i avoid this exception " New topic
Author

How do i avoid this exception

chinomso ikwuagwu
Greenhorn

Joined: Mar 28, 2006
Posts: 11
tableOne and tableTwo are temporary tables which i need to delete from the database.
However the method createTable throws an exception @ line 7 and the tables don't get
deleted. Details of the exception thrown are attached...

Note:
Both tableOne and tableTwo hold references to the same Connection 'con'.




1 public JDBCAdapter createTable(Connection con, String name1, String name2, String newTableName) throws SQLException {

2 JDBCAdapter tableOne = this.createDBTable(con, "SELECT * FROM [" + name1 + "]");

3 JDBCAdapter tableTwo = this.createDBTable(con, "SELECT * FROM [" + name2 + "]");

4 JDBCAdapter returnVal = createAgreedTable(con, tableOne, tableTwo, newTableName);

5 try {

6 Statement s = tableOne.getConnection().createStatement();

7 s.executeUpdate("DROP TABLE [" + tableOne.getName() + "]");

8 s.executeUpdate("DROP TABLE [" + tableTwo.getName() + "]");

9 }catch(SQLException se) {

10se.printStackTrace();

11 }

12 setAdapter(returnVal);

13 return returnVal;

14 }


Exception Thrown at line 10 reads...

sun.jdbc.odbc.JdbcOdbcBatchUpdateException: [Microsoft][ODBC Microsoft Access Driver] The database engine could not lock table 'DISTINCT113' because it is already in use by another person or process.at sun.jdbc.odbc.JdbcOdbcStatement.emulateBatchUpdate(JdbcOdbcStatement.java:1020)at sun.jdbc.odbc.JdbcOdbcStatement.executeBatchUpdate(JdbcOdbcStatement.java:878)at sun.jdbc.odbc.JdbcOdbcStatement.executeBatch(JdbcOdbcStatement.java:862)
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Close your Database (design mode of Microsoft Access)and then try to modify it.

This error will occur

[Vendor][ODBC Driver] The database engine could not lock table 'TableName' because it is already in use by another person or process.


when your database is open for editing and you try to modify it.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

You can retrieves the update count for each update statement in the batch update that executed successfully before this exception occurred through getUpdateCounts Mehtod of BatchUpdateException class.

for more information see Java Doc BatchUpdateException

or you can go for these steps to retrieving information from a BatchUpdateException Steps
 
wood burning stoves
 
subject: How do i avoid this exception