<%@page contentType="text/html;charset=gb2312"%>
<%@page import="java.sql.*"%>
<html>
<head>
<title>lock</title>
</head>
<body>
<%
String jdbcstr="org.gjt.mm.mysql.Driver"; //jdbc类
String constr="jdbc:mysql://localhost:3306/test"; //连结sql 
String user="root"; //用户名
String password=""; //密码
String table="menu"; //操作的数据表
Class.forName(jdbcstr); //加载并实例化数据库jdbc驱动类
Connection con; //连结
Statement statement; //连结的statement 
ResultSet rs; //结果集
con=DriverManager.getConnection(constr); //建立连结
statement=con.createStatement(); //建立statement
String query="LOCK TABLES menu READ"; //设置查询数据库纪录数量的sql语句
statement.executeQuery(query); //查询数据库
query="INSERT INTO menu VALUES ( '54', '51', 'ok', '#', 'yes')";
statement.executeQuery(query);
%>
</body>
</html>这里我首先执行
String query="LOCK TABLES menu READ"; 
statement.executeQuery(query);
来设置menu表为只读。
然后用
query="INSERT INTO menu VALUES ( '54', '51', 'ok', '#', 'yes')";
statement.executeQuery(query);
来向menu写入纪录,结果系统报错,看看大概意思就是说menu表为READ,不能向表内写入纪录。
如果想解除READ状态,这个不用我说你也知道的就是unlock tables