<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost:3306/zaft?user=root&password=hikarutt&useUnicode=true&characterEncoding=GB2312";
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate("insert into abc values('6','艾森')");
}
%>
<%out.print("数据库操作成功,恭喜你");%>
<%
stm.close();
conn.close();
%>
</body>
</html>
上面是我的代码,可是就是不对.请高手们帮忙,最后写一下代码,十分感谢.
<%@ page import="java.sql.*"%>
<html>
<body>
<%
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost:3306/zaft?user=root&password=hikarutt&useUnicode=true&characterEncoding=GB2312";
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate("insert into abc values('6','艾森')");
}
%>
<%out.print("数据库操作成功,恭喜你");%>
<%
stm.close();
conn.close();
%>
</body>
</html>
上面是我的代码,可是就是不对.请高手们帮忙,最后写一下代码,十分感谢.
楼主【athrunzalatt】截止到2008-07-31 10:11:03的历史汇总数据(不包括此帖):
发帖的总数量:6 发帖的总分数:91 每贴平均分数:15
回帖的总数量:79 得分贴总数量:17 回帖的得分率:21%
结贴的总数量:5 结贴的总分数:71
无满意结贴数:0 无满意结贴分:0
未结的帖子数:1 未结的总分数:20
结贴的百分比:83.33 % 结分的百分比:78.02 %
无满意结贴率:0.00 % 无满意结分率:0.00 %
楼主加油
取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=athrunzalatt
stmt.executeUpdate("insert into abc values('6','艾森')");
String sql="insert into abc values('6','艾森')"
stmt.executeUpdate("sql");
这样是不行的,
我再问一个简单的东西,就是我在别的页面上加一个文本框,名字是name
后面写一个number=request.getParameter("name")之后
后面那个插入语句怎么写?
这么写 ?
insert into abc values('number','艾森')?
这一套这么写呢?
继续请教一下大家,谢谢大家帮忙~
String sql="insert into abc values('6','艾森')"
stmt.executeUpdate("sql");
改成
String sql="insert into abc values('6','艾森')"
stmt.executeUpdate(sql);
可是不行
//insert2.jsp
<%@ page contentType="text/html;charset=gb2312"%>
<html>
<body>
<form action="insert.jsp">
<input type=text name="id">
<input type=text name="name">
<input type="submit" name="submit" value="确认">
<input type="reset" name="reset" value="重写">
</form>
</body>
</html>//insert.jsp
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost:3306/zaft?user=root&password=hikarutt&useUnicode=true&characterEncoding=GB2312";
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String a=request.getParameter("id");
String b=request.getParameter("name");
stmt.executeUpdate("insert into abc values('a','b')");%>
<%out.print("数据库操作成功,恭喜你");%>
<%
stmt.close();
conn.close();
%></body>
</html>
我估计问题就是这块有问题:
String a=request.getParameter("id");
String b=request.getParameter("name");
stmt.executeUpdate("insert into abc values('a','b')");