<%@ 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>
上面是我的代码,可是就是不对.请高手们帮忙,最后写一下代码,十分感谢.

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【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
      

  2.   

    你把代码放到try...catch...块里,看报什么错!
      

  3.   

    Statement stmt=conn.createStatement(); 
    stmt.executeUpdate("insert into abc values('6','艾森')"); 
      

  4.   

    或用conn.createStatement(Result.TYPE_SCROLL_INSENITIVE, ResultSet.CONCUR_READ_ONLY);
      

  5.   

    自己弄了一下,已经可以运行了,跟diy8187的方法一样.
    String sql="insert into abc values('6','艾森')"
    stmt.executeUpdate("sql");
    这样是不行的,
    我再问一个简单的东西,就是我在别的页面上加一个文本框,名字是name
    后面写一个number=request.getParameter("name")之后
    后面那个插入语句怎么写?
    这么写 ?
    insert into abc values('number','艾森')?
    这一套这么写呢?
    继续请教一下大家,谢谢大家帮忙~
      

  6.   


    String sql="insert into abc values('6','艾森')" 
    stmt.executeUpdate("sql"); 
    改成
    String sql="insert into abc values('6','艾森')" 
    stmt.executeUpdate(sql); 
      

  7.   

    7楼的方法貌似不行,我刚才试了一下,我记得我第一写就是这么写的,这样的格式跟查询的很像.下面是我写的
    可是不行
    //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')");
      

  8.   

    stmt.executeUpdate("insert into abc values('"+id+"','"+name+"')");