向oracle数据库加入记录

wujing0327 2006-03-13 04:50:19
操作数据库的javabean
package opendb;
import java.sql.*;
import oracle.jdbc.driver.*;
import java.lang.*;
public class opendb
{
//定义数据库连接字符串
String sDBDriver="oracle.jdbc.driver.OracleDriver";
String sConnStr="jdbc:oracle:thin:@192.168.0.9:1521:oracle";
Connection conn=null;
ResultSet rs=null;
//定义打开数据库连接的函数
public opendb()
{
try{
Class.forName(sDBDriver).newInstance();}
catch(java.lang.ClassNotFoundException e){
System.err.println("opendb():"+e.getMessage());}
catch(java.lang.InstantiationException e){
System.err.println("opendb():"+e.getMessage());}
catch(java.lang.IllegalAccessException e){
System.err.println("opendb():"+e.getMessage());}

}
//定义执行sql语句的函数
public ResultSet executeQuery(String sql)
{
rs=null;
try
{
conn=DriverManager.getConnection(sConnStr,"sde","sdrs");
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}
//处理异常
catch(SQLException ex){
System.err.println("aq.executeQuery:"+ex.getMessage());}
return rs;
}
//add or update
public boolean executeUpdate(String sql)
{
boolean bupdate=false;
rs = null;
try
{
conn = DriverManager.getConnection(sConnStr,"sde","123");
Statement stmt = conn.createStatement();
int rowCount = stmt.executeUpdate(sql);
if(rowCount!=0) bupdate=true;
}
catch(SQLException ex) {

System.err.println("db.executeUpdate: " + ex.getMessage());
}
return bupdate;
}

}
插入数据的jsp
<%@ page contentType="text/html;charset=GB2312"%>
<html>
<head>
<title>注册成功</title>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<style type="text/css">
<!--@ import "css/jsp.css";-->
</style>
<body bgcolor="#FFFFFF" text="#000000">
<%@page language="java" import="java.sql.*"
import="javax.sql.*"%>
<jsp:useBean id="db" scope="page" class="opendb.opendb"/>
<%
//读取表单内容
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=gender.getBytes("ISO8859-1");
gender=new String(tmpbyte);
String pwd=request.getParameter("pwd");
String realname=request.getParameter("realname");
tmpbyte=realname.getBytes("ISO8859-1");
realname=new String(tmpbyte);
String career=request.getParameter("career");
tmpbyte=career.getBytes("ISO8859-1");
career=new String(tmpbyte);
String address=request.getParameter("address");
tmpbyte=address.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;
//sql命令
String sql="insert into admin.custom(uid,nickname,gender,pwd,realname,career,address,email,tel,birth) values("+uid+","+nickname+","+gender+","+pwd+","+realname+","+career+","+address+","+email+","+tel+","+birth+")";
//将记录添加到数据库
boolean bupdate=db.executeUpdate(sql);
%>
<p><font color="#CC0033"><%=uid%></font>祝贺您!您的信息已经添加到数据库.</p>
<p align="center"><a href="default.jsp">回到首页</a></p>
</body>
</html>
我用的是tomcat5027,j2sdk1.4.2,在页面上已经成功显示信息已经添加到数据库,但是在oracle数据库中却没有记录
请高手帮忙看看
...全文
67 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
yxxx 2006-03-13
先把你的sql打印出来,然后执行一下,确定sql语句没有问题
回复
wujing0327 2006-03-13
哪个语句的问题呢,我看不出来,还请帮忙看看
回复
QWERT520 2006-03-13
语句有问题
回复
feihn 2006-03-13
db.prepareStatement(insert into admin.custom(uid,nickname,gender,pwd,realname,career,address,email,tel,birth) values(?,?,?));
db.setInt(1,uid);
db.setString(2,nickname);
........
db.executeUpdate();
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2006-03-13 04:50
社区公告
暂无公告