最后关闭链接的代码演示,select不使用任何锁

<?php

$UserName = 'abc';
$Password = '8sj27s';
$DbHandle = mysql_connect ('localhost', $UserName, $Password);
if (!$DbHandle) {
  die 'No database connection could be established.';
}

mysql_close ($DbHandle);
?>
Connection conn = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://" + ip + ":3306/"
                    + dbName, user, pwd);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block

            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

sqlserver

    // 得到数据库连接
    public Connection getConn(String server, String dbname, String u, String pwd)
            throws Exception {
        String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        String URL = "jdbc:sqlserver://" + server + ":1433" + ";DatabaseName="
                + dbname;
        String user = u;
        String password = pwd;
        System.out.println(URL);
        // 注册驱动
        Class.forName(driver).newInstance();
        // 获得数据库连接
        conn = DriverManager.getConnection(URL, user, password);
        return conn;
    }

在ms
sql中可以通过with(nolock)选项指定查询不锁表,在mysql中没有这个选项,需要通过set语句来设置不锁表:

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ;
SELECT * FROM TABLE_NAME ;
COMMIT ;

发表评论

电子邮件地址不会被公开。 必填项已用*标注

标签:, , , , , , ,
网站地图xml地图