标签: sql

  • servlet版sql在线工具

    servlet版sql在线工具,以下是执行sql的核心部分。
    以前用java写过一个同样的工具。现在想起当时对编程还是缺乏经验,对于出错处理,文本识别方面考虑不周,写的也不够规范。附上java版sql 工具。以供自己警记。

    public void executeSql(String sql, HttpServletResponse response)
       throws ServletException, IOException {

       PrintWriter out = response.getWriter();
       try {
         //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection con = DriverManager.getConnection("jdbc:odbc:JavaWeb");
         System.out.println("got connection");
    (更多…)

  • Should I Keep the Connection Open?

    写数据库程序的时候每次进行数据库相关操作结束后都马上加句connection.close;关闭与数据库的连接。从来没有人说明这是个惯例,还是必须,所有的范例都是这么写,却都没有解释,保持数据库连接不是更好么?现代数据库不是都支持并行操作的?为什么还要这样。今天我有了自己的看法。

    All the examples given up to this point in this chapter have closed the Connection object after the servlet services the request. However, you might ask the following question: If the servlet is called more than once and it opens a Connection object with the same arguments (url, user, and password) each time, wouldn’t it better to leave the Connection object open for future use; that is, for when the servlet is called again?
    (更多…)