executeUpdate public int executeUpdate(String sql) throws SQLException Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement. Parameters: sql - an SQL INSERT, UPDATE or DELETE statement or an SQL statement that returns nothing Returns: either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing Throws: SQLException - if a database access error occurs or the given SQL statement produces a ResultSet object
Rst.next(); 这句干吗?
next public boolean next() throws SQLException Moves the cursor down one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on. If an input stream is open for the current row, a call to the method next will implicitly close it. A ResultSet object's warning chain is cleared when a new row is read. Returns: true if the new current row is valid; false if there are no more rows Throws: SQLException - if a database access error occurs
执行SQL语句返回是整数吗?
可以说详细点吗?我是第一次做这种程序
有些东西不太懂的呀,呵呵~是个菜鸟哦:)
是不是跟JAVA里面那样用RETURN 呀
还是其他的方法?
public int executeUpdate(String sql)
throws SQLException
Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement. Parameters:
sql - an SQL INSERT, UPDATE or DELETE statement or an SQL statement that returns nothing
Returns:
either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing
Throws:
SQLException - if a database access error occurs or the given SQL statement produces a ResultSet object
这句干吗?
public boolean next()
throws SQLException
Moves the cursor down one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on.
If an input stream is open for the current row, a call to the method next will implicitly close it. A ResultSet object's warning chain is cleared when a new row is read.
Returns:
true if the new current row is valid; false if there are no more rows
Throws:
SQLException - if a database access error occurs
这句干吗?加上与注销掉都是一样的呀?
{
//admin_id=Rst.getString("admin_id");
admin_user=Rst.getString("admin_user");
admin_power=Rst.getInt("admin_power");
}
你是只想取最后一条记录的信息吗?建议你使用if(Rst.next()) {}在执行新的sql前,
rs.close()
stmt.close()接下来再生成statement,最后执行并关闭。
这样子可以运行的呀
而且可以更改数据库的呀
打印出来的的结果是0
{
stmt.executeUpdate(sql);
int aa=0;
aa=stmt.executeUpdate(sql);
out.print(aa);----aa is 1;
}
{
admin_power=admin_power+1; String sql="update admin set admin_power="+admin_power+" where admin_id="+admin_id+""; Rst.next();
//Stmt.executeUpdate(sql);
^^-----------------------------------这里被你注释掉了,sql将不被执行.
//Conn.commit();
int updateCount=0;
updateCount=Stmt.executeUpdate(sql);//这里只是返回一个int型的值,并不执行sql
if(updateCount>0)
{
out.print("有"+updateCount+"条记录更新成功");
}
else
{
out.print("更新失败");
} } }
Connection con = DriverManager.getConnection("jdbc:odbc:"+dsnname+"",""+DBusername+"",""+DBpwd+"");
java.sql.Statement stmt = con.createStatement();
ResultSet rs;你确定已经连上数据库了??
我怎么没看见你的con?
我在上面用<%@ include file="data.jsp"%>
调用的
还有我可以把数据库里的东西掉出来但就是不能
修改呀:)
可以把你的QQ告诉我吗?
我好更好的向你请教可以吗?
或者邮箱也可以
<%@ page import="java.sql.*" %><%
java.sql.Connection Conn;
java.sql.Statement Stmt;
java.sql.ResultSet Rst;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Conn=DriverManager.getConnection("jdbc:odbc:soft2","lx","lx");
Stmt=Conn.createStatement();String submit=request.getParameter("Submit");
String admin_id=request.getParameter("admin_id");
String admin_user="";
int admin_power=0;if(submit!=null)
{ if(submit.equals("提升"))
{
Rst=Stmt.executeQuery("select * from admin where admin_id="+admin_id+""); if(Rst.next())
{
//admin_id=Rst.getString("admin_id");
admin_user=Rst.getString("admin_user");
admin_power=Rst.getInt("admin_power");
}
if(admin_power!=30)
{
admin_power=admin_power+1;
String sql="update admin set admin_power="+admin_power+"where admin_id="+admin_id+"";
Rst.next();
Stmt.executeUpdate(sql);
//Conn.commit();
int updateCount=0;
updateCount=Stmt.executeUpdate(sql);
out.print(updateCount);
if(updateCount>0)
{
out.print("有"+updateCount+"条记录更新成功");
}
else
{
out.print("更新失败");
} }
// return(sql);}
/* else if(submit.equals("下降"))
{
Rst=Stmt.executeQuery("select * from admin where admin_id="+admin_id);
while(Rst.next())
{
admin_user=Rst.getString("admin_user");
admin_power=Rst.getInt("admin_power");
}
if(admin_power!=0)
{
admin_power=admin_power-1;
String sql="update admin set admin_power=3 where admin_id=4";//+admin_id;
Rst.next();
Stmt.executeUpdate(sql);
}
}*/
//Rst.close();
//Stmt.close();
//}
}
%>
<html>
<head>
<title>
用户管理
</title>
</head>
<body bgcolor="FFFFFF" text="000000">
<div align="center"><b><font color="#FF6600">会员信息管理</font></b>
<table width="760" border="0" cellspacing="2" cellpadding="2" bgcolor="#000000">
<tr bgcolor="FFFFFF">
<td height="20" width="259">用户名</td>
<td height="20" width="300">用户等级</td>
<td height="20" width="181">等级提降</td>
</tr>
<%
// int admin_id=0;
// String admin_user="";
// int admin_power=0;
int I;
//int mum=0;
//int p_id=request.getParameter("admin_id");
//ResultSet Rs=soft.executeQuery("select max(admin_power) as maxorderpower,min(admin_pwoer) as minorderpower from admin where admin_id="+p_id+"");
Rst=Stmt.executeQuery("select max(admin_power) as maxorderpower,min(admin_power) as minorderpower from admin");Rst.next();
int maxorderpower=Rst.getInt("maxorderpower");
int minorderpower=Rst.getInt("minorderpower");
//ResultSet Rs=soft.executeQuery("select * from admin order by admin_power desc");
Rst=Stmt.executeQuery("select * from admin order by admin_power desc");
while(Rst.next())
{
//admin_id=Rs.getInt("admin_id");
admin_user=Rst.getString("admin_user");
admin_power=Rst.getInt("admin_power");
// mum=Rs.getInt("admin_id");
%>
<tr>
<td width="259" bgcolor="#F3F3F3"><%=admin_user%></td>
<td width="300" bgcolor="#F3F3F3"><%=admin_power%></td>
<td width="181" bgcolor="#F3F3F3">
<form name="form1" method="post" action="">
<input type="hidden" name="h_power" value="<%=admin_power%>">
<%if(admin_power!=maxorderpower)%>
<input type="submit" name="Submit" value="提升">
<%if(admin_power!=minorderpower)%>
<input type="submit" name="Submit"value="下降">
</form>
</td>
</tr>
<%
}
%>
</table>
</div>
</body>
</html>
代码都在这里了呀:)
麻烦帮我看看;)