Invalid parameter binding(s)

bb5460 2006-06-14 01:13:33
编译JSP文件时,Eclipse控制台提示报错信息是:java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid parameter binding(s).但仔细检查了参数绑定并无发现错误,且将对应的JAVA文件编译成JAVA应用程序也是成功的。请高手指教。
...全文
1630 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhouzhijun 2007-03-31
  • 打赏
  • 举报
回复
JSP中导入就出错了吧,<%@ page import="util.*" %>,而应该是<%@ page import="java.util.*" %>
bb5460 2006-06-14
  • 打赏
  • 举报
回复
toSql主要实现字符格式的转换,刚才根据你的意见,去掉了这个方法,仍然不行。另外我的sql脚本是:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[users]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[users]
GO

CREATE TABLE [dbo].[users] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[UserName] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
[PassWord] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO

请帮帮忙,谢谢

kevinliuu 2006-06-14
  • 打赏
  • 举报
回复
既然是prepareStatement出现的问题,就好好查查

ps.setString(1,strFormat.toSql(this.getUsername()));
ps.setString(2,strFormat.toSql(this.getPasswd()));

这两句,你的toSql方法做了什么?
bb5460 2006-06-14
  • 打赏
  • 举报
回复
另外,当我把JAVA组件中用prepareStatement实现的部分改为,用Statement时,一切正常,JSP页面能正确显示。很是奇怪,我用的JDBC驱动是微软的,用了连接池技术,相应的数据库是MS SQLSERVER 2000,请大家帮帮忙,谢谢
bb5460 2006-06-14
  • 打赏
  • 举报
回复
我的JAVA组件代码如下(包含部分测试代码):
/*
* 创建日期 2006-6-12
*
* 更改所生成文件模板为
* 窗口 > 首选项 > Java > 代码生成 > 代码和注释
*/
package operator;

/**
*<p>管理用户登录的类 </p>
*/

import java.util.*;
import util.*;
import java.sql.*;

public class login {
private String username="";
private String passwd="";
private boolean isadmin=false; //是否管理员登录
private int userid=0;
public String sqlStr="";

private sql_data db; //数据库连接池实例
private Connection con=null; //数据连接对像
private Statement stmt=null;
private ResultSet rs=null; //数据查询结果集
private PreparedStatement ps=null;//数据库操作执行状态对象

public login() {
username="";
passwd="";
isadmin=false;
userid=0;

}


public void setUsername(String name){
this.username=name;
}
public String getUsername(){
return this.username;
}

public void setPasswd(String psw){
this.passwd=psw;
}
public String getPasswd(){
return this.passwd;
}


public void setIsadmin(boolean Isadmin){
this.isadmin=Isadmin;
}
public boolean getIsadmin(){
return this.isadmin;
}

public void setUserid(int nid){
this.userid=nid;
}
public int getUserid(){
return this.userid;
}


/**
*获得查询用户信息的SQL语句
*/
public String getSql(){
if(isadmin){
sqlStr="select * from admin where adminuser=? and adminpass=?";
}else{
sqlStr="select * from users where username=?and password=?";
}

return sqlStr;
}

/**
*执行查询
*/

public boolean exectue() throws Exception{
db=sql_data.getInstance();
con=db.getConnection("idb");
boolean flag=false;
try{
//stmt=con.createStatement();
//rs=stmt.executeQuery(getSql());

ps=con.prepareStatement(getSql());
ps.clearParameters();
ps.setString(1,strFormat.toSql(this.getUsername()));
ps.setString(2,strFormat.toSql(this.getPasswd()));
rs=ps.executeQuery();

// if(rs.next()){
// if(!isadmin){
// userid=rs.getInt("id");
//
// }
//
// flag=true;
// freeCon();
// }
}catch(Exception e){
flag=false;

System.out.println(e.getMessage());
}

return flag;




}


/**
* 释放数据库资源
* PrepareStatement和ResultSet都将关闭,Connection返回给连接池
*/
public void freeCon(){
try{
if(rs!=null) rs.close();
if(ps!=null) ps.close();
//if(stmt!=null) stmt.close();
}catch(Exception e){

}
if(db!=null)
db.freeConnection("idb",con);
}

public static void main(String[] args ){

login l=new login();
l.setIsadmin(false);
l.setUsername("1");
l.setPasswd("1");
try{

if(l.exectue())
System.out.println(l.getUserid());
else
System.out.println(l.getPasswd()+l.getUsername());
}catch(Exception e){

System.out.println("exception");
}

}
}

bb5460 2006-06-14
  • 打赏
  • 举报
回复
我的JSP页面代码如下(其中包含部分测试代码):
<%@ page contentType="text/html; charset=gb2312" %>

<%@ page import="util.*" %>
<%@ page import="operator.*" %>
<%@ page import="asset.*"%>


<%
login login=new login();
String mesg = "";

if( request.getParameter("username")!=null && !request.getParameter("username").equals("")){
String username =request.getParameter("username");

String passwd = request.getParameter("passwd");
login.setUsername(username);
login.setPasswd(passwd);
login.setIsadmin(false);



if(login.exectue()){
session.setAttribute("username",username);
String userid = Integer.toString(login.getUserid());
session.setAttribute("userid",userid);
response.sendRedirect("assetlist.jsp");
}
else
mesg = "登录出错!" ;
out.println(login.getSql());
out.println(login.getUsername());
out.println(login.getPasswd());
out.println(login.getUserid());



}
%>


<script language="javascript">

function checkform() {
if (document.form1.username.value=="" || document.form1.passwd.value==""){
alert("用户名或密码为空!");
return false;
}
return true;

}

</script>

<html>
<body>
<div align=center>用户登录 </div>
<br>
<% if (!mesg.equals("")){
out.println("<p>" + mesg + "</p>");}
%>

<form name="form1" method="post" action="login1.jsp">
<table width="400" border="0" cellspacing="1" cellpadding="1" align="center">
<tr>
<td width="147" align="right">用户名:<br>
</td>
<td width="246" valign="top">
<input type="text" name="username" size="16" maxlength="25">
</td>
</tr>
<tr>
<td width="147" align="right">密码:</td>
<td width="246" valign="top">
<input type="password" name="passwd" maxlength="20" size="16">
</td>
</tr>
<tr>
<td width="147" align="right"> </td>
<td width="246" valign="top">
<input type="submit" name="Submit" value="登录" onclick="javascript:return(checkform());">
<input type="reset" name="Submit2" value="取消">
</td>
</tr>

</table>
</form>
</body></html>
Delphi 7.1 Update Release Notes=======================================================This file contains important supplemental and late-breakinginformation that may not appear in the main productdocumentation, and supersedes information contained in otherdocuments, including previously installed release notes.Borland recommends that you read this file in its entirety.NOTE: If you are updating a localized version of Delphi 7, visit the Borland Registered User web site to obtain a localized readme file that may contain important late- breaking information not included in this readme file.IMPORTANT: Delphi must be closed before installing this update. =====================================================CONTENTS * INSTALLING THIS UPDATE * UPDATING LOCALIZED VERSIONS OF DELPHI 7 * KNOWN ISSUES * ISSUES ADDRESSED BY THIS UPDATE - IDE - CORE DATABASE - DATASNAP - DBGO (ADO COMPONENTS) - dbExpress - dbExpress COMPONENTS AND DB VCL - dbExpress CORE DRIVER AND METADATA - dbExpress VENDOR ISSUES - dbExpress CERTIFICATION - WEB SNAP - ACTIVEX - COMPILER - RTL - VCL - THIRD PARTY - BOLD FOR DELPHI * VERIFYING THAT THE UPDATE WAS SUCCESSFUL * FILES INSTALLED BY THIS UPDATE =======================================================INSTALLING THIS UPDATE* This update can not be applied to Delphi 7 Architect Trial version. * This update can not be removed after it is installed.* You will need the original Delphi 7 installation CD available to install this update.* To install this update from the CD, insert the CD, and launch the d7_ent_upd1.exe file appropriate for your locale.* To install this update from the Web, double-click the self-executing installation file and follow the prompts. * The Delphi 7 documentation PDF files are available on the update CD.========================================================UPDATING LOCALIZED VERSIONS OF DELPHI 7* This update can be applied only to the English version of Delphi 7. There are separate updates for the German, French and Japanese ver
You are visitor as of October 17, 1996.The Art of Assembly Language ProgrammingForward Why Would Anyone Learn This Stuff?1 What's Wrong With Assembly Language2 What's Right With Assembly Language?3 Organization of This Text and Pedagogical Concerns4 Obtaining Program Source Listings and Other Materials in This TextSection One: Machine OrganizationArt of Assembly Language: Chapter OneChapter One - Data Representation1.0 - Chapter Overview1.1 - Numbering Systems1.1.1 - A Review of the Decimal System1.1.2 - The Binary Numbering System1.1.3 - Binary Formats1.2 - Data Organization1.2.1 - Bits1.2.2 - Nibbles1.2.3 - Bytes1.2.4 - Words1.2.5 - Double Words1.3 - The Hexadecimal Numbering System1.4 - Arithmetic Operations on Binary and Hexadecimal Numbers1.5 - Logical Operations on Bits1.6 - Logical Operations on Binary Numbers and Bit Strings1.7 - Signed and Unsigned Numbers1.8 - Sign and Zero Extension1.9 - Shifts and Rotates1.10 - Bit Fields and Packed Data1.11 - The ASCII Character Set1.12 Summary1.13 Laboratory Exercises1.13.1 Installing the Software1.13.2 Data Conversion Exercises1.13.3 Logical Operations Exercises1.13.4 Sign and Zero Extension Exercises1.13.5 Packed Data Exercises1.14 Questions1.15 Programming ProjectsChapter Two - Boolean Algebra2.0 - Chapter Overview2.1 - Boolean Algebra2.2 - Boolean Functions and Truth Tables2.3 - Algebraic Manipulation of Boolean Expressions2.4 - Canonical Forms2.5 - Simplification of Boolean Functions2.6 - What Does This Have To Do With Computers, Anyway?2.6.1 - Correspondence Between Electronic Circuits and Boolean Functions2.6.2 - Combinatorial Circuits2.6.3 - Sequential and Clocked Logic2.7 - Okay, What Does It Have To Do With Programming, Then?2.8 - Generic Boolean Functions2.9 Laboratory Exercises<

81,115

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧