SQLite Tutorial
forName("org.sqlite.JDBC"); c = DriverManager.getConnection("jdbc:sqlite:test.db"); } catch ( Exception e ) { System.err.println( e.getClass().getName() + ": " + e.getMessage() ); SALARY REAL)"; stmt.executeUpdate(sql); stmt.close(); c.close(); } catch ( Exception e ) { System.err.println( e.getClass().getName() + ": " + e.getMessage() ); stmt.executeUpdate(sql); stmt.close(); c.commit(); c.close(); } catch ( Exception e ) { System.err.println( e.getClass().getName() + ": " + e.getMessage() );0 码力 | 172 页 | 1.27 MB | 1 年前3使用JDBC连接数据库
注意一下数据库连接 字符串 麻烦的关闭代码 由于数据库连接是一种比较昂贵 的资源,所以,必须保证关闭。 由于Connection对象的close() 方法会抛出异常,所以不得不嵌 套try/catch结构…… 事实上,不仅Connection需 要关闭,Statement和 ResultSet其实也是需要即 时关闭的…… 简化代码…… 将需要自动关闭的对象放到try 表达式中,这是推荐的编码方式。0 码力 | 20 页 | 1.02 MB | 1 年前3
共 2 条
- 1