jsp预编译这个例题。。怎么也做不出来。。
来源:百度知道 编辑:UC知道 时间:2024/08/21 17:11:56
预编译不成功...
odbc已经建立pufan,并指向phonebook.
<%@page import="java.sql.*"%>
<%@page contentType="text/html;charset=GB2312"%>
<%
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:pufan";
String updata = "UPDATE phonebook"
+"set phone=?,addr=?"
+"where name=1";
try
{
Class.forName(driver);
}
catch(Exception e)
{
e.printStackTrace();
out.println("<br>"+"can't loading driver! ");
}
try
{
Connection con = DriverManager.getConnection(url);
PreparedStatement psmt = con.prepareStatement(updata);
psmt.setString('1',"wanglan");
psmt.setString('2',"wangyu");
psmt.setString('3',"wangfang");
odbc已经建立pufan,并指向phonebook.
<%@page import="java.sql.*"%>
<%@page contentType="text/html;charset=GB2312"%>
<%
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:pufan";
String updata = "UPDATE phonebook"
+"set phone=?,addr=?"
+"where name=1";
try
{
Class.forName(driver);
}
catch(Exception e)
{
e.printStackTrace();
out.println("<br>"+"can't loading driver! ");
}
try
{
Connection con = DriverManager.getConnection(url);
PreparedStatement psmt = con.prepareStatement(updata);
psmt.setString('1',"wanglan");
psmt.setString('2',"wangyu");
psmt.setString('3',"wangfang");
第一个:
PreparedStatement psmt的用法有错误
setString的参数是setString(int ,String),而不是setString(String, String)
把
psmt.setString('1',"wanglan");
psmt.setString('2',"wangyu");
psmt.setString('3',"wangfang");
改成
psmt.setString(1,"wanglan");
psmt.setString(2,"wangyu");
psmt.setString(3,"wangfang");
第二个:
在String updata 中只有两个“?”,后面怎么设置了三个参数?这样在运行时还是会出错
第三个:
你数据库里面name字段的数据类型是什么?如果是varchar,where name=1应该写成where name='1'
虽然有些数据库可以兼容这种写法,不过还是规范一点好