在cmd下连接、插入、查询等操作都正常,但是用java连接derby数据库时总是出现如下错误:
java.sql.SQLTransactionRollbackException:A lock could not be obtained within the time requested
private Connection getConnection()
{
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
conn=DriverManager.getConnection("jdbc:derby:qq;create=true");
conn.setAutoCommit(false);
return conn;
}
public void insert(String tName)
{
String sql="insert into "+tName+"(id,email,count) values(4,'dfsqq,22)";
this.excuteSQL(sql);
}
public boolean excuteSQL(String sql)
{
Statement s;
conn=getConnection();
s = conn.createStatement();
s.executeUpdate(sql);
s.close();
//conn.close() 会出现关闭异常,提示:连接正处于活动状态**
return true;
}
public void close()
{
try
{
conn.close();
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Dao dao=new Dao();
dao.insert(table);//出现异常
dao.close();