23 个解决方案
#1
把异常信息贴出来
#2
try
{Connection con;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:link");
PreparedStatement prepStmt=con.prepareStatement(sql);
prepStmt.setString(1,username);
prepStmt.setString(2,password);
prepStmt.setString(3,usertruename);
prepStmt.setInt(4,ageint);
prepStmt.setString(5,sex);
prepStmt.setString(6,address);
prepStmt.setString(7,telephone);
prepStmt.executeUpdate(sql);
con.close();
}
catch(SQLException e1)
{
out.print("SQL err!");
}
异常信息就是catch(){}里写的内容.
{Connection con;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:link");
PreparedStatement prepStmt=con.prepareStatement(sql);
prepStmt.setString(1,username);
prepStmt.setString(2,password);
prepStmt.setString(3,usertruename);
prepStmt.setInt(4,ageint);
prepStmt.setString(5,sex);
prepStmt.setString(6,address);
prepStmt.setString(7,telephone);
prepStmt.executeUpdate(sql);
con.close();
}
catch(SQLException e1)
{
out.print("SQL err!");
}
异常信息就是catch(){}里写的内容.
#3
为什么没有人继续回贴了?
#4
第一,你没把异常打出来,第二sql的内容看不到,所以没法回答,还有你的代码写的实在有点问题
#5
可能有各种错误,把e1.getMessage()打出来看看,或许是因为表建的有问题
#6
在地址栏写入http://127.0.0.1:8080/accept1.jsp
页面显示 SQL err!
(accept1.jsp为接受上个页面内容,向数据库写记录.
数据库表为user,内容为name password truename age sex address telephone)
页面显示 SQL err!
(accept1.jsp为接受上个页面内容,向数据库写记录.
数据库表为user,内容为name password truename age sex address telephone)
#7
在catch中打印printStackTrace(),看一下异常详细信息
#8
没有显示e1.getMessage()内容.
#9
数据表user中各个列为
name char 10
password char 10
truename char 10
age int 4
sex char 10
address char 10
telephone char 10
其中name 不能为空
name char 10
password char 10
truename char 10
age int 4
sex char 10
address char 10
telephone char 10
其中name 不能为空
#10
把catch(SQLException e1)
{
out.print("SQL err!");
}
改为catch(SQLException ex)
{
ex.printStackTrace();
}
后,页面没有异常信息.
{
out.print("SQL err!");
}
改为catch(SQLException ex)
{
ex.printStackTrace();
}
后,页面没有异常信息.
#11
看不到sql语句的内容,请楼主把sql语句的内容贴出来。
#12
String sql;
sql="insert into user(name,password,truename,age,sex,address,telephone)values(?,?,?,?,?,?,?)";
sql="insert into user(name,password,truename,age,sex,address,telephone)values(?,?,?,?,?,?,?)";
#13
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<%@ page isErrorPage="true" %>
<html>
<body>
<%!
public String codeToString(String str)
{
String s=str;
try
{
byte tempB[]=s.getBytes("ISO-8859-1");
s=new String(tempB);
return s;
}
catch(Exception e)
{
return s;
}
}
%>
<%
String username=codeToString(request.getParameter("username"));
if(username==null)
username="";
String password=codeToString(request.getParameter("password"));
if(password==null)
password="";
String usertruename=codeToString(request.getParameter("usertruename"));
if(usertruename==null)
usertruename="";
String age=codeToString(request.getParameter("age"));
int ageint;
try
{
ageint=Integer.parseInt(age.trim());
}
catch(Exception e)
{
ageint=0;
}
String sex=codeToString(request.getParameter("sex"));
if(sex==null)
sex="";
String address=codeToString(request.getParameter("address"));
if(address==null)
address="";
String telephone=codeToString(request.getParameter("telephone"));
if(telephone==null)
telephone="";
%>
<%
String sql;
sql="insert into user(name,password,truename,age,sex,address,telephone)values(?,?,?,?,?,?,?)";
%>
<%
try
{Connection con;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:link");
PreparedStatement prepStmt=con.prepareStatement(sql);
prepStmt.setString(1,username);
prepStmt.setString(2,password);
prepStmt.setString(3,usertruename);
prepStmt.setInt(4,ageint);
prepStmt.setString(5,sex);
prepStmt.setString(6,address);
prepStmt.setString(7,telephone);
prepStmt.executeUpdate(sql);
con.close();
}
catch(SQLException ex)
{
System.err.println("err:"+ex.getMessage());
}
%>
<center>
<table border="1" width="700">
<tr>
<td width="100%" colspan="2" align="center">用户注册程序</td>
</tr>
<tr>
<td width="100%" colspan="2" align="center">追加用户成功</td>
</tr>
</body>
</html>
<%@ page import="java.sql.*" %>
<%@ page isErrorPage="true" %>
<html>
<body>
<%!
public String codeToString(String str)
{
String s=str;
try
{
byte tempB[]=s.getBytes("ISO-8859-1");
s=new String(tempB);
return s;
}
catch(Exception e)
{
return s;
}
}
%>
<%
String username=codeToString(request.getParameter("username"));
if(username==null)
username="";
String password=codeToString(request.getParameter("password"));
if(password==null)
password="";
String usertruename=codeToString(request.getParameter("usertruename"));
if(usertruename==null)
usertruename="";
String age=codeToString(request.getParameter("age"));
int ageint;
try
{
ageint=Integer.parseInt(age.trim());
}
catch(Exception e)
{
ageint=0;
}
String sex=codeToString(request.getParameter("sex"));
if(sex==null)
sex="";
String address=codeToString(request.getParameter("address"));
if(address==null)
address="";
String telephone=codeToString(request.getParameter("telephone"));
if(telephone==null)
telephone="";
%>
<%
String sql;
sql="insert into user(name,password,truename,age,sex,address,telephone)values(?,?,?,?,?,?,?)";
%>
<%
try
{Connection con;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:link");
PreparedStatement prepStmt=con.prepareStatement(sql);
prepStmt.setString(1,username);
prepStmt.setString(2,password);
prepStmt.setString(3,usertruename);
prepStmt.setInt(4,ageint);
prepStmt.setString(5,sex);
prepStmt.setString(6,address);
prepStmt.setString(7,telephone);
prepStmt.executeUpdate(sql);
con.close();
}
catch(SQLException ex)
{
System.err.println("err:"+ex.getMessage());
}
%>
<center>
<table border="1" width="700">
<tr>
<td width="100%" colspan="2" align="center">用户注册程序</td>
</tr>
<tr>
<td width="100%" colspan="2" align="center">追加用户成功</td>
</tr>
</body>
</html>
#14
现在打印的是什么错啊
#15
prepStmt.executeUpdate(sql);把里面的SQL去掉
直接prepStmt.executeUpdate();
你的sql都在prepStmt里了,还放括号里干什么
直接prepStmt.executeUpdate();
你的sql都在prepStmt里了,还放括号里干什么
#16
回复:freedom2001(天翔)
谢谢,我去掉了,可是数据库里面还是没有内容.
谢谢,我去掉了,可是数据库里面还是没有内容.
#17
sql="insert into user(name,password,truename,age,sex,address,telephone)values('"+username+"','"+password+"','"+usertruename+"',age,sex,'"+address+"',telephone)";
我假设你的 AGE SEX 和TELEPHONE这3个字段是数字行 你的SQL语句是这样吗
我假设你的 AGE SEX 和TELEPHONE这3个字段是数字行 你的SQL语句是这样吗
#18
问题终于解决了.
#19
那恭喜你
#20
请问怎么给各位分?
#21
kuy
#22
真没有心情看!
#23
out.print("SQL err!");
^_^!
^_^!
#1
把异常信息贴出来
#2
try
{Connection con;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:link");
PreparedStatement prepStmt=con.prepareStatement(sql);
prepStmt.setString(1,username);
prepStmt.setString(2,password);
prepStmt.setString(3,usertruename);
prepStmt.setInt(4,ageint);
prepStmt.setString(5,sex);
prepStmt.setString(6,address);
prepStmt.setString(7,telephone);
prepStmt.executeUpdate(sql);
con.close();
}
catch(SQLException e1)
{
out.print("SQL err!");
}
异常信息就是catch(){}里写的内容.
{Connection con;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:link");
PreparedStatement prepStmt=con.prepareStatement(sql);
prepStmt.setString(1,username);
prepStmt.setString(2,password);
prepStmt.setString(3,usertruename);
prepStmt.setInt(4,ageint);
prepStmt.setString(5,sex);
prepStmt.setString(6,address);
prepStmt.setString(7,telephone);
prepStmt.executeUpdate(sql);
con.close();
}
catch(SQLException e1)
{
out.print("SQL err!");
}
异常信息就是catch(){}里写的内容.
#3
为什么没有人继续回贴了?
#4
第一,你没把异常打出来,第二sql的内容看不到,所以没法回答,还有你的代码写的实在有点问题
#5
可能有各种错误,把e1.getMessage()打出来看看,或许是因为表建的有问题
#6
在地址栏写入http://127.0.0.1:8080/accept1.jsp
页面显示 SQL err!
(accept1.jsp为接受上个页面内容,向数据库写记录.
数据库表为user,内容为name password truename age sex address telephone)
页面显示 SQL err!
(accept1.jsp为接受上个页面内容,向数据库写记录.
数据库表为user,内容为name password truename age sex address telephone)
#7
在catch中打印printStackTrace(),看一下异常详细信息
#8
没有显示e1.getMessage()内容.
#9
数据表user中各个列为
name char 10
password char 10
truename char 10
age int 4
sex char 10
address char 10
telephone char 10
其中name 不能为空
name char 10
password char 10
truename char 10
age int 4
sex char 10
address char 10
telephone char 10
其中name 不能为空
#10
把catch(SQLException e1)
{
out.print("SQL err!");
}
改为catch(SQLException ex)
{
ex.printStackTrace();
}
后,页面没有异常信息.
{
out.print("SQL err!");
}
改为catch(SQLException ex)
{
ex.printStackTrace();
}
后,页面没有异常信息.
#11
看不到sql语句的内容,请楼主把sql语句的内容贴出来。
#12
String sql;
sql="insert into user(name,password,truename,age,sex,address,telephone)values(?,?,?,?,?,?,?)";
sql="insert into user(name,password,truename,age,sex,address,telephone)values(?,?,?,?,?,?,?)";
#13
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<%@ page isErrorPage="true" %>
<html>
<body>
<%!
public String codeToString(String str)
{
String s=str;
try
{
byte tempB[]=s.getBytes("ISO-8859-1");
s=new String(tempB);
return s;
}
catch(Exception e)
{
return s;
}
}
%>
<%
String username=codeToString(request.getParameter("username"));
if(username==null)
username="";
String password=codeToString(request.getParameter("password"));
if(password==null)
password="";
String usertruename=codeToString(request.getParameter("usertruename"));
if(usertruename==null)
usertruename="";
String age=codeToString(request.getParameter("age"));
int ageint;
try
{
ageint=Integer.parseInt(age.trim());
}
catch(Exception e)
{
ageint=0;
}
String sex=codeToString(request.getParameter("sex"));
if(sex==null)
sex="";
String address=codeToString(request.getParameter("address"));
if(address==null)
address="";
String telephone=codeToString(request.getParameter("telephone"));
if(telephone==null)
telephone="";
%>
<%
String sql;
sql="insert into user(name,password,truename,age,sex,address,telephone)values(?,?,?,?,?,?,?)";
%>
<%
try
{Connection con;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:link");
PreparedStatement prepStmt=con.prepareStatement(sql);
prepStmt.setString(1,username);
prepStmt.setString(2,password);
prepStmt.setString(3,usertruename);
prepStmt.setInt(4,ageint);
prepStmt.setString(5,sex);
prepStmt.setString(6,address);
prepStmt.setString(7,telephone);
prepStmt.executeUpdate(sql);
con.close();
}
catch(SQLException ex)
{
System.err.println("err:"+ex.getMessage());
}
%>
<center>
<table border="1" width="700">
<tr>
<td width="100%" colspan="2" align="center">用户注册程序</td>
</tr>
<tr>
<td width="100%" colspan="2" align="center">追加用户成功</td>
</tr>
</body>
</html>
<%@ page import="java.sql.*" %>
<%@ page isErrorPage="true" %>
<html>
<body>
<%!
public String codeToString(String str)
{
String s=str;
try
{
byte tempB[]=s.getBytes("ISO-8859-1");
s=new String(tempB);
return s;
}
catch(Exception e)
{
return s;
}
}
%>
<%
String username=codeToString(request.getParameter("username"));
if(username==null)
username="";
String password=codeToString(request.getParameter("password"));
if(password==null)
password="";
String usertruename=codeToString(request.getParameter("usertruename"));
if(usertruename==null)
usertruename="";
String age=codeToString(request.getParameter("age"));
int ageint;
try
{
ageint=Integer.parseInt(age.trim());
}
catch(Exception e)
{
ageint=0;
}
String sex=codeToString(request.getParameter("sex"));
if(sex==null)
sex="";
String address=codeToString(request.getParameter("address"));
if(address==null)
address="";
String telephone=codeToString(request.getParameter("telephone"));
if(telephone==null)
telephone="";
%>
<%
String sql;
sql="insert into user(name,password,truename,age,sex,address,telephone)values(?,?,?,?,?,?,?)";
%>
<%
try
{Connection con;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:link");
PreparedStatement prepStmt=con.prepareStatement(sql);
prepStmt.setString(1,username);
prepStmt.setString(2,password);
prepStmt.setString(3,usertruename);
prepStmt.setInt(4,ageint);
prepStmt.setString(5,sex);
prepStmt.setString(6,address);
prepStmt.setString(7,telephone);
prepStmt.executeUpdate(sql);
con.close();
}
catch(SQLException ex)
{
System.err.println("err:"+ex.getMessage());
}
%>
<center>
<table border="1" width="700">
<tr>
<td width="100%" colspan="2" align="center">用户注册程序</td>
</tr>
<tr>
<td width="100%" colspan="2" align="center">追加用户成功</td>
</tr>
</body>
</html>
#14
现在打印的是什么错啊
#15
prepStmt.executeUpdate(sql);把里面的SQL去掉
直接prepStmt.executeUpdate();
你的sql都在prepStmt里了,还放括号里干什么
直接prepStmt.executeUpdate();
你的sql都在prepStmt里了,还放括号里干什么
#16
回复:freedom2001(天翔)
谢谢,我去掉了,可是数据库里面还是没有内容.
谢谢,我去掉了,可是数据库里面还是没有内容.
#17
sql="insert into user(name,password,truename,age,sex,address,telephone)values('"+username+"','"+password+"','"+usertruename+"',age,sex,'"+address+"',telephone)";
我假设你的 AGE SEX 和TELEPHONE这3个字段是数字行 你的SQL语句是这样吗
我假设你的 AGE SEX 和TELEPHONE这3个字段是数字行 你的SQL语句是这样吗
#18
问题终于解决了.
#19
那恭喜你
#20
请问怎么给各位分?
#21
kuy
#22
真没有心情看!
#23
out.print("SQL err!");
^_^!
^_^!