你要用bean.
package bean;import java.sql.*;
import java.lang.*;public class adduser extends db{
//constructor
public boolean addNewUser(){
boolean boadduser=false;
try{
String sSql=new String("insert into user(Id,name,time)");
sSql=sSql+" values (\'"+Id+"\',\'"+Name+"\',\'"+Time+"\',\')";
System.out.println("");
System.out.println("SQL is: ");
System.out.println(sSql);
if(super.executeUpdate(sSql))
boadduser=true;
}
catch(Exception e){
System.err.println("adduser.addNewUser: "+e.getMessage());
}
finally{
return boadduser;
}
}
//set & get method use for jsp
public String getId(){
return Id;
}
public void setId(String newId){
Id=newId;
}
public String getName(){
return Name;
}
public void setName(String newName){
Name=newName;
}
public String getTime(){
return Time;
}
public void setTime(String newTime){
Time=newTime;
}
}
package bean;import java.sql.*;
import java.lang.*;public class adduser extends db{
//constructor
public boolean addNewUser(){
boolean boadduser=false;
try{
String sSql=new String("insert into user(Id,name,time)");
sSql=sSql+" values (\'"+Id+"\',\'"+Name+"\',\'"+Time+"\',\')";
System.out.println("");
System.out.println("SQL is: ");
System.out.println(sSql);
if(super.executeUpdate(sSql))
boadduser=true;
}
catch(Exception e){
System.err.println("adduser.addNewUser: "+e.getMessage());
}
finally{
return boadduser;
}
}
//set & get method use for jsp
public String getId(){
return Id;
}
public void setId(String newId){
Id=newId;
}
public String getName(){
return Name;
}
public void setName(String newName){
Name=newName;
}
public String getTime(){
return Time;
}
public void setTime(String newTime){
Time=newTime;
}
}
解决方案 »
- JSP:out.println(66.6d);为什么没有输出??
- jsp中frame跳转的问题
- msxsml6.0 xsl:import
- 再问,一个从action向jspPage传值得问题。
- 傻瓜问题啊
- resin服务器问题,显示:Server busy, please try again later,有人遇到过吗?
- 我是新手 请教如何在JSP上上传和下载文件?
- 配置好datasource后 居然无法连接mysql
- 《精通Eclipse Web开发--Java体系结构、工具、框架及整合应用》
- 大家帮忙推荐免费的jsp论坛资源下载
- 字符串比较==和equals有什么区别?
- jbuilder9+weblogic6.0+sqlServer配置问题,在线等!!!!
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%!public String gToi(String s)
{if(s==null)
s="";
try{byte a[]=s.getBytes("ISO-8859-1");
s=new String(a);}
catch(Exception e)
{}
return s;
}
%>
<%
Calendar cal = Calendar.getInstance();
java.util.Date d = cal.getTime();
int pp=(int)(d.getYear()+1900);
String year=String.valueOf(pp);
int qq=(int)(d.getMonth()+1);
String month=String.valueOf(qq); int tt=(int)(d.getDate());
String date=String.valueOf(tt);
String shijian=String.valueOf(year+"-"+month+"-"+date);
String content=request.getParameter("Content");
String title=request.getParameter("title");
String tclass=request.getParameter("Tclass");
content=gToi(content);
title=gToi(title);
tclass=gToi(tclass);
Connection con=null;
Statement sql;
ResultSet rs;
try{Class.forName("jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e){}
try{con=DriverManager.getConnection("jdbc:odbc:qingdaojob","","");
sql=con.createStatement();
String condition="insert into info"+"("+"title,catname,news,input_date"+")"+" values"+"("+"'"+title+"','"+tclass+"','"+content+"',"+"#"+shijian+"#"+")";
sql.executeUpdate(condition);
out.print("<div align=center>添加成功。请返回!<input type=button onclick=history.back() value=返回><br></div>");
}
catch(SQLException e){out.print("没连上数据库啊!真笨!");}
%>
这是我刚以前写的一段代码。写的比较乱。连数据库没用到bean。
插记录的时候。你要注意时间的插入方式。还有自动编号的字段。你不用插入他的植。只要将其他的值写入就行。自动编号的值会自己加1写入的。呵呵。不知道你懂我的意思不?
ps.setTimestamp(2,new Timestamp(new java.util.date().getTime()));//系统当前时间
ps.executeUpdate();试试看行不
例如:
create sequence Seq_USERLOGIN start with 1 maxvalue 99999999999999999999;
sql="insert into XXX(fid,FTOPID,............) values (Seq_USERLOGIN .nextval,...............)";
id是自动编号的,应该不用插入,所以应该这样写:
sqlInsert = "inseert into menmeber (name, time) values('aaa', '#2003-09-24#)"
id是自动编号的,应该不用插入,所以应该这样写:
sqlInsert = "insert into memeber (name, time) values('aaa', #2003-09-24#)"