jsp连接sqlserver问题
do_login.jsp
<%@ page language="java" contentType="text/html;charset=GB2312"%>
<%@ page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>用户注册界面</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
request.setCharacterEncoding("gb2312");
String s_user=request.getParameter("s_user");
System.out.println(s_user);
String s_pwd=request.getParameter("s_pwd");
String s_real=request.getParameter("s_real");
String s_tel=request.getParameter("s_tel");
String s_address=request.getParameter("s_address");
String s_email=request.getParameter("s_email");
ResultSet rs=null;
Connection conn=null;
Statement stat=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String strConn="jdbc:odbc:wt";
String strUser="wt";
String strPassword="123456";
conn=DriverManager.getConnection(strConn,strUser,strPassword);
stat=conn.createStatement();
String strSql="insert into shopuser(username,pwd,realname,tel,address,email) values('"+s_user+"','"+s_pwd+"','"+s_real+"','"+s_tel+"','"+s_address+"','"+s_email+"')";
System.out.print(strSql);
int a=stat.executeUpdate(strSql);
if(a>0)
{
out.print("<font size=4pt color='red'>"+ "用户添加成功!"+"</font>");
}
else
{
out.print("<font size=4pt color='red'>"+"用户添加失败!"+"</font>");
}
}
catch(Exception e)
{
out.println(e.toString());
}
%>
<%
if(rs!=null)
{
rs.close();
}
if(stat!=null)
{
stat.close();
}
if(conn!=null)
{
conn.close();
}
%>
</body>
</html>
老是出现:java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]不允许从数据类型 varchar 到 varbinary 的隐式转换。请使用 CONVERT 函数来运行此查询。
[解决办法]
String strSql="insert into shopuser(username,pwd,realname,tel,address,email) values('"+s_user+"','"+s_pwd+"','"+s_real+"','"+s_tel+"','"+s_address+"','"+s_email+"')";
username,pwd,realname,tel,address,email这几个字段中有一个是varbinary类型的,估计你的pwd是此类型的,看下是否有这样的字段