提交页面为:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,open.*" errorPage="" %>
<jsp:useBean id="db" scope="page" class="open.opendb" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>注册成功</title>
</head>
<body>
<%
String uid=request.getParameter("uid");
String nickname=request.getParameter("nickname");
byte[] tmpbyte=nickname.getBytes("ISO8859_1");
nickname=new String(tmpbyte);
String gender=request.getParameter("gender");
tmpbyte=nickname.getBytes("ISO8859_1");
gender=new String (tmpbyte);
String pwd=request.getParameter("pwd");
String realname=request.getParameter("realname");
tmpbyte=nickname.getBytes("ISO8859_1");
realname=new String(tmpbyte);
String career=request.getParameter("career");
tmpbyte=nickname.getBytes("ISO8859_1");
career=new String(tmpbyte);
String address=request.getParameter("address");
tmpbyte=nickname.getBytes("ISO8859_1");
address=new String(tmpbyte);
String email=request.getParameter("email");
String tel=request.getParameter("tel");
String year=request.getParameter("year");
String month=request.getParameter("month");
String day=request.getParameter("day");
String birth=year+"-"+month+"-"+day;
String sql="insert custom (uid,nickname,gender,pwd,realname,career,address,email,tel,birth) values ('"+uid+"','"+nickname+"','"+gender+"','"+pwd+"','"+realname+"','"+career+"','"+address+"','"+email+"','"+tel+"','"+birth+"')";
db.executeUpdate(sql);
%>
<p><font color="#FF0000"><%=uid%></font>:祝贺你,你的信息已经添加到数据库中</p>
<p align="center"><a href="default.jsp">回到首页</a></p>
</body>
</html>
15 个解决方案
#1
用的JavaBean为:
package open;
import java.sql.*;
public class opendb
{
//String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
Connection con=null;
ResultSet rs=null;
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=JSP";
String user="sa";
String password="123456";
public opendb()
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
}
catch(java.lang.ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
catch(Exception s)
{
System.out.println(s.getMessage());
}
}
public ResultSet execute(String sql)
{
rs=null;
try
{
con=DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement();
rs=stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.out.println(ex.getMessage());
}
catch(Exception s)
{
System.out.println(s.getMessage());
}
return rs;
}
public void executeUpdate(String sql)
{
try
{
con=DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException e)
{
System.out.println("sqlexception:"+e);
}
catch(Exception e)
{
System.out.println("an unknow error occured");
}
}
}
package open;
import java.sql.*;
public class opendb
{
//String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
Connection con=null;
ResultSet rs=null;
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=JSP";
String user="sa";
String password="123456";
public opendb()
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
}
catch(java.lang.ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
catch(Exception s)
{
System.out.println(s.getMessage());
}
}
public ResultSet execute(String sql)
{
rs=null;
try
{
con=DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement();
rs=stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.out.println(ex.getMessage());
}
catch(Exception s)
{
System.out.println(s.getMessage());
}
return rs;
}
public void executeUpdate(String sql)
{
try
{
con=DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException e)
{
System.out.println("sqlexception:"+e);
}
catch(Exception e)
{
System.out.println("an unknow error occured");
}
}
}
#2
望各位指点:)谢谢!
#3
少写了个into吧
insert into custom ......
insert into custom ......
#4
最好捕捉一下异常
try{
String uid=request.getParameter("uid");
String nickname=request.getParameter("nickname");
byte[] tmpbyte=nickname.getBytes("ISO8859_1");
nickname=new String(tmpbyte);
String gender=request.getParameter("gender");
tmpbyte=nickname.getBytes("ISO8859_1");
gender=new String (tmpbyte);
String pwd=request.getParameter("pwd");
String realname=request.getParameter("realname");
tmpbyte=nickname.getBytes("ISO8859_1");
realname=new String(tmpbyte);
String career=request.getParameter("career");
tmpbyte=nickname.getBytes("ISO8859_1");
career=new String(tmpbyte);
String address=request.getParameter("address");
tmpbyte=nickname.getBytes("ISO8859_1");
address=new String(tmpbyte);
String email=request.getParameter("email");
String tel=request.getParameter("tel");
String year=request.getParameter("year");
String month=request.getParameter("month");
String day=request.getParameter("day");
String birth=year+"-"+month+"-"+day;
String sql="insert custom (uid,nickname,gender,pwd,realname,career,address,email,tel,birth) values ('"+uid+"','"+nickname+"','"+gender+"','"+pwd+"','"+realname+"','"+career+"','"+address+"','"+email+"','"+tel+"','"+birth+"')";
db.executeUpdate(sql);
}catch(Exception e){
System.out.println(e);
}
try{
String uid=request.getParameter("uid");
String nickname=request.getParameter("nickname");
byte[] tmpbyte=nickname.getBytes("ISO8859_1");
nickname=new String(tmpbyte);
String gender=request.getParameter("gender");
tmpbyte=nickname.getBytes("ISO8859_1");
gender=new String (tmpbyte);
String pwd=request.getParameter("pwd");
String realname=request.getParameter("realname");
tmpbyte=nickname.getBytes("ISO8859_1");
realname=new String(tmpbyte);
String career=request.getParameter("career");
tmpbyte=nickname.getBytes("ISO8859_1");
career=new String(tmpbyte);
String address=request.getParameter("address");
tmpbyte=nickname.getBytes("ISO8859_1");
address=new String(tmpbyte);
String email=request.getParameter("email");
String tel=request.getParameter("tel");
String year=request.getParameter("year");
String month=request.getParameter("month");
String day=request.getParameter("day");
String birth=year+"-"+month+"-"+day;
String sql="insert custom (uid,nickname,gender,pwd,realname,career,address,email,tel,birth) values ('"+uid+"','"+nickname+"','"+gender+"','"+pwd+"','"+realname+"','"+career+"','"+address+"','"+email+"','"+tel+"','"+birth+"')";
db.executeUpdate(sql);
}catch(Exception e){
System.out.println(e);
}
#5
上面说的对!
#6
我觉得是insert into吧?
#7
INSERT 语句的完整句法如下:
INSERT [INTO] {table_name|view_name} [(column_list)] {DEFAULT VALUES |
Values_list | select_statement}
into是可选的
应该是有异常,你看一下
INSERT [INTO] {table_name|view_name} [(column_list)] {DEFAULT VALUES |
Values_list | select_statement}
into是可选的
应该是有异常,你看一下
#8
问题解决了,就是少写了个into
晕我太粗心了:)
散分。
晕我太粗心了:)
散分。
#9
个人觉得还是要写完整点好,习惯问题,只是建议,呵呵~~~
#10
学习学习。
另, jsp取得数据的方法用servlet重写不是更好吗?
这样工作就可分工了,找名初中生帮忙用网页工具开发用户界面,自己写servlet, 然后请他吃个汉堡就完了,省去很多工夫。
另, jsp取得数据的方法用servlet重写不是更好吗?
这样工作就可分工了,找名初中生帮忙用网页工具开发用户界面,自己写servlet, 然后请他吃个汉堡就完了,省去很多工夫。
#11
呵呵,说的很实际
努力学习,天天向上
努力学习,天天向上
#12
哇,这么久了,此帖悬而未决嘛!:)
#13
我帮忙顶一下吧:-)
#14
呵呵,简单的错误,我也经常犯
#15
INSERT [INTO] {table_name|view_name} [(column_list)] {DEFAULT VALUES |
Values_list | select_statement}
into是可选的
除了严格按照语法去code外,还要注意异常的发生。
Values_list | select_statement}
into是可选的
除了严格按照语法去code外,还要注意异常的发生。
#1
用的JavaBean为:
package open;
import java.sql.*;
public class opendb
{
//String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
Connection con=null;
ResultSet rs=null;
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=JSP";
String user="sa";
String password="123456";
public opendb()
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
}
catch(java.lang.ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
catch(Exception s)
{
System.out.println(s.getMessage());
}
}
public ResultSet execute(String sql)
{
rs=null;
try
{
con=DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement();
rs=stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.out.println(ex.getMessage());
}
catch(Exception s)
{
System.out.println(s.getMessage());
}
return rs;
}
public void executeUpdate(String sql)
{
try
{
con=DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException e)
{
System.out.println("sqlexception:"+e);
}
catch(Exception e)
{
System.out.println("an unknow error occured");
}
}
}
package open;
import java.sql.*;
public class opendb
{
//String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
Connection con=null;
ResultSet rs=null;
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=JSP";
String user="sa";
String password="123456";
public opendb()
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
}
catch(java.lang.ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
catch(Exception s)
{
System.out.println(s.getMessage());
}
}
public ResultSet execute(String sql)
{
rs=null;
try
{
con=DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement();
rs=stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.out.println(ex.getMessage());
}
catch(Exception s)
{
System.out.println(s.getMessage());
}
return rs;
}
public void executeUpdate(String sql)
{
try
{
con=DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException e)
{
System.out.println("sqlexception:"+e);
}
catch(Exception e)
{
System.out.println("an unknow error occured");
}
}
}
#2
望各位指点:)谢谢!
#3
少写了个into吧
insert into custom ......
insert into custom ......
#4
最好捕捉一下异常
try{
String uid=request.getParameter("uid");
String nickname=request.getParameter("nickname");
byte[] tmpbyte=nickname.getBytes("ISO8859_1");
nickname=new String(tmpbyte);
String gender=request.getParameter("gender");
tmpbyte=nickname.getBytes("ISO8859_1");
gender=new String (tmpbyte);
String pwd=request.getParameter("pwd");
String realname=request.getParameter("realname");
tmpbyte=nickname.getBytes("ISO8859_1");
realname=new String(tmpbyte);
String career=request.getParameter("career");
tmpbyte=nickname.getBytes("ISO8859_1");
career=new String(tmpbyte);
String address=request.getParameter("address");
tmpbyte=nickname.getBytes("ISO8859_1");
address=new String(tmpbyte);
String email=request.getParameter("email");
String tel=request.getParameter("tel");
String year=request.getParameter("year");
String month=request.getParameter("month");
String day=request.getParameter("day");
String birth=year+"-"+month+"-"+day;
String sql="insert custom (uid,nickname,gender,pwd,realname,career,address,email,tel,birth) values ('"+uid+"','"+nickname+"','"+gender+"','"+pwd+"','"+realname+"','"+career+"','"+address+"','"+email+"','"+tel+"','"+birth+"')";
db.executeUpdate(sql);
}catch(Exception e){
System.out.println(e);
}
try{
String uid=request.getParameter("uid");
String nickname=request.getParameter("nickname");
byte[] tmpbyte=nickname.getBytes("ISO8859_1");
nickname=new String(tmpbyte);
String gender=request.getParameter("gender");
tmpbyte=nickname.getBytes("ISO8859_1");
gender=new String (tmpbyte);
String pwd=request.getParameter("pwd");
String realname=request.getParameter("realname");
tmpbyte=nickname.getBytes("ISO8859_1");
realname=new String(tmpbyte);
String career=request.getParameter("career");
tmpbyte=nickname.getBytes("ISO8859_1");
career=new String(tmpbyte);
String address=request.getParameter("address");
tmpbyte=nickname.getBytes("ISO8859_1");
address=new String(tmpbyte);
String email=request.getParameter("email");
String tel=request.getParameter("tel");
String year=request.getParameter("year");
String month=request.getParameter("month");
String day=request.getParameter("day");
String birth=year+"-"+month+"-"+day;
String sql="insert custom (uid,nickname,gender,pwd,realname,career,address,email,tel,birth) values ('"+uid+"','"+nickname+"','"+gender+"','"+pwd+"','"+realname+"','"+career+"','"+address+"','"+email+"','"+tel+"','"+birth+"')";
db.executeUpdate(sql);
}catch(Exception e){
System.out.println(e);
}
#5
上面说的对!
#6
我觉得是insert into吧?
#7
INSERT 语句的完整句法如下:
INSERT [INTO] {table_name|view_name} [(column_list)] {DEFAULT VALUES |
Values_list | select_statement}
into是可选的
应该是有异常,你看一下
INSERT [INTO] {table_name|view_name} [(column_list)] {DEFAULT VALUES |
Values_list | select_statement}
into是可选的
应该是有异常,你看一下
#8
问题解决了,就是少写了个into
晕我太粗心了:)
散分。
晕我太粗心了:)
散分。
#9
个人觉得还是要写完整点好,习惯问题,只是建议,呵呵~~~
#10
学习学习。
另, jsp取得数据的方法用servlet重写不是更好吗?
这样工作就可分工了,找名初中生帮忙用网页工具开发用户界面,自己写servlet, 然后请他吃个汉堡就完了,省去很多工夫。
另, jsp取得数据的方法用servlet重写不是更好吗?
这样工作就可分工了,找名初中生帮忙用网页工具开发用户界面,自己写servlet, 然后请他吃个汉堡就完了,省去很多工夫。
#11
呵呵,说的很实际
努力学习,天天向上
努力学习,天天向上
#12
哇,这么久了,此帖悬而未决嘛!:)
#13
我帮忙顶一下吧:-)
#14
呵呵,简单的错误,我也经常犯
#15
INSERT [INTO] {table_name|view_name} [(column_list)] {DEFAULT VALUES |
Values_list | select_statement}
into是可选的
除了严格按照语法去code外,还要注意异常的发生。
Values_list | select_statement}
into是可选的
除了严格按照语法去code外,还要注意异常的发生。