首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

为什么小弟我的jsp数据库更新不了,哪位老师帮帮忙看看

2012-01-19 
为什么我的jsp数据库更新不了,哪位老师帮帮忙看看%@pagecontentType text/htmlcharsetgb2312 %%@p

为什么我的jsp数据库更新不了,哪位老师帮帮忙看看
<%@   page   contentType= "text/html;charset=gb2312 "%>
<%@   page   import= "java.sql.* "%>
<html>
<body>
<%
//获取提交的姓名
String   name=request.getParameter( "name ");
if(name==null)
{
    name= " ";
}
name=new   String(name.getBytes( "ISO8859_1 "), "gb2312 ");
//out.print(name);
//获取提交的新的数学成绩
String   newMath=request.getParameter( "math ");
if(newMath==null)
{
    newMath= "-100 ";
}
//out.print(newMath);
//获取提交的新的英语成绩
String   newEnglish=request.getParameter( "english ");
if(newEnglish==null)
{
    newEnglish= "-100 ";
}
//out.print(newEnglish);
//获取提交的新的物理成绩
String   newPhysics=request.getParameter( "physics ");
if(newPhysics==null)
{
    newPhysics= "-100 ";
}
//out.print(newPhysics);
Connection   con;
Statement   sql;
ResultSet   rs;
try
{
    Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
}
catch(ClassNotFoundException   e)
{}
try
{
    con=DriverManager.getConnection( "jdbc:odbc:student ", "sa ", "123 ");
    sql=con.createStatement();
    String   condition1=
                  "update   students   set   mscore= "+newMath+
                  "where   name= ' "+name+ " ' ";
    String   condition2=
                  "update   students   set   escore= "+newEnglish+
                  "where   name= ' "+name+ " ' ";
    String   condition3=
                  "update   students   set   pscore= "+newPhysics+
                  "where   name= ' "+name+ " ' ";

    //执行更新操作
    sql.executeUpdate(condition1);
    sql.executeUpdate(condition2);
    sql.executeUpdate(condition3);

    //显示更新后的表中的记录
%>
<p> 更新后的表的记录:
<%
    rs=sql.executeQuery( "select   *   from   students ");
    out.println( " <table   border=1> ");
    out.println( " <tr> ");
        out.println( " <th   width=100> "+ "学号 ");
        out.println( " <th   width=100> "+ "姓名 ");
        out.println( " <th   width=50> "+ "数学成绩 ");
        out.println( " <th   width=50> "+ "英语成绩 ");
        out.println( " <th   width=50> "+ "物理成绩 ");
    out.println( " </tr> ");
while(rs.next())
{
    out.print( " <tr> ");
        out.print( " <td> "+rs.getString(1)+ " </td> ");


        out.print( " <td> "+rs.getString(2)+ " </td> ");
        out.print( " <td> "+rs.getInt( "mscore ")+ " </td> ");
        out.print( " <td> "+rs.getInt( "escore ")+ " </td> ");
        out.print( " <td> "+rs.getInt( "pscore ")+ " </td> ");
    out.print( " </tr> ");
}
out.print( " </table> ");
con.close();
}
catch(SQLException   e1)
{}
%>
</body>
</html>


[解决办法]
你把你的sql语句打出来看看,语句绝对错了
我没说错的话应该是(比如你的newMath=80,name=lisi)

update students set mscore=80where name= 'lisi '
[解决办法]
开始写上getAutoCommit(false);
...........
最后commit() ;


[解决办法]
String condition1=
"update students set mscore= "+newMath+
"where name= ' "+name+ " ' ";
String condition2=
"update students set escore= "+newEnglish+
"where name= ' "+name+ " ' ";
String condition3=
"update students set pscore= "+newPhysics+
"where name= ' "+name+ " ' ";

-------------------------------------------
正如Top
YOYOOOP
说得.
你的sql生成时  update students set mscore=80where name= 'lisi '
应该在where 前加空格
[解决办法]

[解决办法]
呵呵

热点排行