How to use JDBC in JavaEE?

穿精又带淫゛_ 提交于 2019-12-06 09:28:41

Why should using JDBC be bad practice?

If your application server supports JDBC and you let him connect to a DB via JDBC I, for myself, see no reason why you shouldn't use it in your application, too!?

Another approach would be to load the driver manually in your application and get a connection from it. But this would be like reinventing the wheel!

Also you dismiss the advantage of

  • the server side management of your JDBC connection-pool
  • the reusability of this connection

At the end you should always close your Connection/Statement/ResultSet like:

try {
  // your stuff here
}
finally {
  if(connection != null) {
    connection.close();
  }
  // same for statement/ResultSet ift not used anymore
}

close the connection- conn.close();

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!