求:小型数据库系统(添加、修改、删除,更新)源代码

rocker1218 2004-05-09 04:58:24
100分求购"添加"功能的願代码!
界面中有code,name,count,company,note 五个字段,界面是有jsp实现,功能是由java(servlet)来实现,数据库用Access.
先付二十分.看到代码后,分立即补上.
...全文
153 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yhcdavis 2004-05-12
  • 打赏
  • 举报
回复
package Com.FuHong.Workflow.Mange;

/**
* <p>Title:数据库连接操作公共类 </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
import java.sql.*;

public class OpenDb {
static protected String aa="ss";
protected int z=12;
//final int final1=8;
public static String DBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
public static String DSN ="jdbc:odbc:Jworkflow";
public static String DBuser="sa";
public static String DBpasswd="it474150";
public Connection conn=null;
public Statement stmt=null;
public ResultSet rs=null;
public int id;
boolean isCorrect;

public OpenDb()
{
try{

Class.forName(DBDriver);
}catch(ClassNotFoundException e){
e.printStackTrace();
System.err.println("OpenDb()"+e.getMessage());
}
}



//执行SQL查询语句,返回查询结果集//
public ResultSet ExecuteQuery(String sql) throws SQLException
{
try{
conn=DriverManager.getConnection(DSN,DBuser,DBpasswd);
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}catch(SQLException e){
System.out.print("SQLException"+e.getMessage());
}catch(Exception e){
e.printStackTrace();
}finally{
return rs;
}
}

//执行更新、删除操作,返回更新或删除的记录编号
public int ExecuteUpdate(String sql)
{
try{
conn=DriverManager.getConnection(DSN,DBuser,DBpasswd);
stmt=conn.createStatement();
id=stmt.executeUpdate(sql);
}catch(SQLException e){
e.printStackTrace();
}catch(Exception e){
System.err.print(e.getMessage());
}finally{
return id;
}

}

//执行插入操作
public boolean ExecuteInsert(String sql)
{
isCorrect=false;
try{
conn=DriverManager.getConnection(DSN,DBuser,DBpasswd);
stmt=conn.createStatement();
isCorrect=stmt.execute(sql);
isCorrect=true;

}catch(SQLException e){
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}finally{
return isCorrect;
}
}
}

我刚才不能发了,安我的名字去,可用,(SQL2000)
yhcdavis 2004-05-12
  • 打赏
  • 举报
回复
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="Com.FuHong.Workflow.Mange.OpenDb"%>
<%@ page import="java.sql.*"%>
<%

int getpage= 1; //请求的页
int curpage=1; //当前页
int allrecord=0; //总的

int page_record = 10; //每页显示的固定记录数

String where=" 1=1 ";
String ryxm;
String ryxb;
if(request.getParameter("ryxm")==null&&request.getParameter("ryxb")==null)
{

}else if(request.getParameter("ryxm")!=null&&request.getParameter("ryxb")!=null){
ryxm=new String(request.getParameter("ryxm").getBytes("ISO-8859-1"));
ryxb=new String(request.getParameter("ryxb").getBytes("ISO-8859-1"));
if(ryxm.length()>=1&&ryxb.equals("所有")){
where+=" and ryxm like '%"+ryxm+"%'";
}else if(ryxm.length()>=1&&!ryxb.equals("所有")){
where+=" and ryxm like '%"+ryxm+"%' and ryxb='"+ryxb+"'";
}else if(ryxm.length()<1&&ryxb.equals("所有")){

}else{
where+=" and ryxb='"+ryxb+"'";
}

}
OpenDb open=new OpenDb();
ResultSet rs=null;
String sql="select count(*) from ryxx where "+where;

rs=open.ExecuteQuery(sql);
int count=0;
if(rs.next()){
allrecord=rs.getInt(1);
}
int allpage=(int)Math.ceil((allrecord+page_record-1)/page_record);
//rs.close();
if(request.getParameter("page")==null){
curpage=1;
}else{
getpage=new Integer(request.getParameter("page")).intValue();
getpage=Integer.parseInt(request.getParameter("page"));

if(getpage>allpage){
curpage=allpage;
}else if(getpage<1){
curpage=1;
}else{
curpage=getpage;
}
}

//sql="select * from ryxx "+where;
sql="select top "+page_record+" * from ryxx where "+where+" and ryid not in (select top "+((curpage-1)*page_record)+" ryid from ryxx where "+where+" order by ryid asc) order by ryid asc";
rs=open.ExecuteQuery(sql);
%>
<table border=1 align=center>
<tr><td><form name=form1 action=ryxx.jsp>
<table align=center>
<tr><td>姓名</td><td><input name=ryxm></td><td>性别</td><td><select name=ryxb><option value=所有 selected>所有</option><option value=男>男</option><option value=女>女</option></select></td><td>   <input type=submit name=submit value=查询></td></tr>
</table></form>
</td></tr>
</table>
<%
out.println("<p align=right><a href=./ryxxnew.jsp>新增</a></p>");
out.println("<p align=center><a href=./ryxx.jsp?page=1>首页</a>  <a href=./ryxx.jsp?page="+(curpage-1)+">上一页</a>  <a href=./ryxx.jsp?page="+(curpage+1)+">下一页</a>  <a href=./ryxx.jsp?page="+allpage+">尾页</a>  共"+allpage+"页  共"+allrecord+"项</center>");
out.println("<table border=1 align=center width=600>");
while(rs.next())
{
int ryid=rs.getInt(1);
out.println("<tr><td>"+ryid+"</td><td>"+rs.getString(2)+"</td><td>"+rs.getString(3)+
"</td><td>"+rs.getInt(4)+"</td><td>"+rs.getInt(5)+
"</td><td><a href=./ryxxupdate.jsp?type=delete&ryid="+ryid+" onClick=\"return confirm('是否删除!')\">删除</a>  <a href=./ryxxupdate.jsp?type=update&ryid="+ryid+">修改</a></td></tr>");
}
out.println("<table>");

%>
shiyonggang 2004-05-12
  • 打赏
  • 举报
回复

public static Vector getAllDepart( ) {

int count;
boolean isCorrect=false;
String sql="select * from depart order by DepartID ASC";
Vector allDepart = new Vector();
DBSQL dbsql = new DBSQL();
ResultSet rs = null;

dbsql.openDB();
rs = dbsql.executeQuery(sql);
dbsql.closeDB();

try {
int i=0;
while(rs.next()) {
Depart aDepart = new Depart(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getInt(6));
allDepart.add(aDepart);
isCorrect = true;
i++;
}
}catch (SQLException ex) {
}catch (Exception ex) {
}finally{
return (isCorrect==false)?null:allDepart;
}
}

public static Vector getAllDepart(int Superior) {

int count;
boolean isCorrect=false;
String sql="select * from depart where Superior="+Superior;
Vector allDepart = new Vector();
DBSQL dbsql = new DBSQL();
ResultSet rs = null;

dbsql.openDB();
rs = dbsql.executeQuery(sql);
dbsql.closeDB();

try {
int i=0;
while(rs.next()) {
Depart aDepart = new Depart(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getInt(6));
allDepart.add(aDepart);
isCorrect = true;
i++;
}
}catch (SQLException ex) {
}catch (Exception ex) {
}finally{
return (isCorrect==false)?null:allDepart;
}
}

public static String getDepartName(int DepartID){

boolean isCorrect=false;
String sql="select DepartName from depart where DepartID="+DepartID;
String DepartName = "";
DBSQL dbsql = new DBSQL();
ResultSet rs = null;

dbsql.openDB();
rs = dbsql.executeQuery(sql);
dbsql.closeDB();

try {
if (rs.next()) {
DepartName = rs.getString(1);
isCorrect = true;
}
rs.close();
}
catch (SQLException ex) {

}catch(Exception e){
e.printStackTrace();
}finally{
return(isCorrect==false)?null:DepartName;
}
}

public static int getDepartID(String DepartName){

boolean isCorrect=false;
String sql="select DepartID from depart where DepartName='"+DepartName+"'";
int DepartID = 0;
DBSQL dbsql = new DBSQL();
ResultSet rs = null;

dbsql.openDB();
rs = dbsql.executeQuery(sql);
dbsql.closeDB();

try {
if (rs.next()) {
DepartID = rs.getInt(1);
isCorrect = true;
}
rs.close();
}
catch (SQLException ex) {

}catch(Exception e){
e.printStackTrace();
}finally{
return(isCorrect==false)?-1:DepartID;
}
}

public static boolean isHaveJunior(int DepartID){

boolean isCorrect = false,result = false;
String sql="SELECT count(*) FROM depart where Superior="+DepartID;
DBSQL dbsql = new DBSQL();
ResultSet rs = null;

dbsql.openDB();
rs = dbsql.executeQuery(sql);
dbsql.closeDB();
try {
if (rs.next()) {
if (rs.getInt(1)!=0) {
result = true;
}
isCorrect = true;
}
rs.close();
}
catch (Exception ex) {

}
finally {
return(isCorrect==false)?false:result;
}
}

public static boolean isExist(int DepartID){

boolean isCorrect = false,result = false;
String sql="SELECT count(*) FROM depart where DepartID="+DepartID;
DBSQL dbsql = new DBSQL();
ResultSet rs = null;

dbsql.openDB();
rs = dbsql.executeQuery(sql);
dbsql.closeDB();
try {
if (rs.next()) {
if (rs.getInt(1)!=0) {
result = true;
}
isCorrect = true;
}
rs.close();
}
catch (Exception ex) {
}
finally {
return(isCorrect==false)?false:result;
}
}

}
shiyonggang 2004-05-12
  • 打赏
  • 举报
回复
很容易实现呀,用JAVABEAN就可以了,给你参考以下:
package com.oa.depart;

import com.oa.DBMS.*;
import java.sql.*;
import java.util.*;
/**
* <p>Title: 电子政务系统</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author
* @version 1.0
*/

public class Depart {

private int departID;
private String departName;
private String leader;
private String tel;
private String intro;
private int superior;
public Depart() {

}

public Depart(int departID,String departName,String leader,String tel,String intro,int superior) {

this.departID = departID;
this.departName = departName;
this.leader = leader;
this.tel = tel;
this.intro = intro;
this.superior = superior;

}

public int getDepartID() {
return departID;
}
public void setDepartID(int departID) {
this.departID = departID;
}
public String getDepartName() {
return departName;
}
public void setDepartName(String departName) {
this.departName = departName;
}
public String getLeader() {
return leader;
}
public void setLeader(String leader) {
this.leader = leader;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getIntro() {
return intro;
}
public void setIntro(String intro) {
this.intro = intro;
}
public int getSuperior() {
return superior;
}
public void setSuperior(int superior) {
this.superior = superior;
}

public static void addDepart(Depart adepart) {
DBSQL dbsql = new DBSQL();
String sql="insert into depart(DepartName,Leader,Tel,Intro,Superior) values('"+adepart.getDepartName()+"','"+adepart.getLeader()+"','"+adepart.getTel()+"','"+adepart.getIntro()+"',"+adepart.getSuperior()+")";
dbsql.openDB();
dbsql.executeUpdate(sql);
dbsql.closeDB();
}

public static void delDepart(int DepartID) {
DBSQL dbsql = new DBSQL();
String sql="delete from depart where DepartID="+DepartID;
dbsql.openDB();
dbsql.executeUpdate(sql);
dbsql.closeDB();
}

public static void updateDepart(Depart depart){
DBSQL dbsql = new DBSQL();
String sql="update depart set departName='"+depart.getDepartName()+"',leader='"+depart.getLeader()+"',tel='"+depart.getTel()+"',intro='"+depart.getIntro()+"',Superior="+depart.getSuperior()+" where DepartID="+depart.getDepartID();
dbsql.openDB();
dbsql.executeUpdate(sql);
dbsql.closeDB();
}

public static void updateDepart(int DepartID,String DepartName,String Leader,String Tel,String Intro,int Superior) {
DBSQL dbsql = new DBSQL();
String sql="update depart set DepartName='"+DepartName+"',Leader='"+Leader+"',Tel='"+Tel+"',Intro='"+Intro+"',Superior="+Superior+" where DepartID="+DepartID;
dbsql.openDB();
dbsql.executeUpdate(sql);
dbsql.closeDB();
}

public static int getCount(){

boolean isCorrect=false;
String sql = "SELECT count(*) FROM depart";
int count=0;
ResultSet rs = null;
DBSQL dbsql = new DBSQL();
dbsql.openDB();
rs = dbsql.executeQuery(sql);
dbsql.closeDB();
try {
if (rs.next()) {
count = rs.getInt(1);
isCorrect = true;
}
rs.close();
}
catch (SQLException ex) {

}catch(Exception e){
e.printStackTrace();
}finally{
return(isCorrect==false)?-1:count;
}
}

public static Vector getADepart(int DepartID) {
Vector aDepart = null;
boolean isCorrect=false;
String sql="select * from depart where DepartID="+DepartID;
ResultSet rs = null;
DBSQL dbsql = new DBSQL();
dbsql.openDB();
rs = dbsql.executeQuery(sql);
dbsql.closeDB();
try {
if (rs.next()) {
Depart depart = new Depart(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getInt(6));
aDepart.add(depart);
isCorrect = true;
}
rs.close();
}
catch (SQLException ex) {

}catch(Exception e){
e.printStackTrace();
}finally{
return(isCorrect==false)?null:aDepart;
}
}
yhcdavis 2004-05-12
  • 打赏
  • 举报
回复
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="Com.FuHong.Workflow.Mange.OpenDb"%>
<%
String type=request.getParameter("type");
String ryxm=new String(request.getParameter("ryxm").getBytes("ISO-8859-1"));
String ryxb=new String(request.getParameter("ryxb").getBytes("ISO-8859-1"));
int nl=Integer.parseInt(request.getParameter("nl"));
//double nl=Double.parseDouble(request.getParameter("nl"));
int bjbh=Integer.parseInt(request.getParameter("bjbh"));
OpenDb open=new OpenDb();
if(type.equals("insert")){
String sql="insert into ryxx(ryxm,ryxb,nl,bjbh)"+
"values('"+ryxm+"','"+ryxb+"',"+nl+","+bjbh+")";
out.println(sql);
open.ExecuteInsert(sql);
out.println("新增成功!");
out.println("<meta http-equiv=refresh content=\"3;url=./ryxx.jsp\">");
}else if(type.equals("update")){
int ryid=Integer.parseInt(request.getParameter("ryid"));
String sql="update ryxx set ryxm='"+ryxm+"',ryxb='"+ryxb+"',nl="+nl+",bjbh="+bjbh+" where ryid="+ryid;
open.ExecuteUpdate(sql);
out.println("修改成功!");
out.println("<meta http-equiv=refresh content=\"3;url=./ryxx.jsp\">");

}
%>

yhcdavis 2004-05-12
  • 打赏
  • 举报
回复
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>ryxxnew</title>
<script language=javascript>
function deptcheck(theForm)
{
if(theForm.ryxm.value==""){
alert("姓名不能为空!");
theForm.ryxm.focus();
return (false);
}
if(theForm.nl.value==""){
alert("年龄不能为空");
theForm.nl.focus();
return (false);
}
if(theForm.bjbh.value==""){
alert("班级编号不能为空");
theForm.bjbh.focus();
return (false);
}
return (true);
}

</script>
</head>
<body>
<h1 align=center>人员新增</h1>
<form method="post" action=./ryxxedit.jsp onSubmit="return deptcheck(this)">
<table align=center width=500 border=1 bordercolor=blue>
<tr><td colspan=2 align=center>人员新增<input type=hidden name=type value=insert></td></tr>
<tr><td width=100>姓名</td><td><input type=text name=ryxm></td></tr>
<tr><td>性别</td><td><input type=radio name=ryxb value="男" checked>男<input type=radio name=ryxb value="女">女</td></tr>
<tr><td>年龄</td><td><input name=nl></td></tr>
<tr><td>班级</td><td><input type=text name=bjbh size=50></td></tr>
<tr><td colspan=2 align=center>
<input type="submit" name="Submit" value="保存">
<input type="reset" value="重填"></td></tr>
</table>
<p align=right><a hrer="#" onClick="history.back(1)">返回</a></p>
</form>
</body>
</html>
yhcdavis 2004-05-12
  • 打赏
  • 举报
回复
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.sql.*"%>
<%@ page import="Com.FuHong.Workflow.Mange.OpenDb"%>
<%
OpenDb open =new OpenDb();
String ryxxidStr=request.getParameter("ryid");
int ryid=Integer.parseInt(ryxxidStr);
String type=request.getParameter("type");
out.println(ryid);

if(type.equals("delete"))//执行删除操作
{
String sql="delete from ryxx where ryid="+ryid;
open.ExecuteUpdate(sql);
out.println("删除成功");
out.print("<meta http-equiv=refresh content=\"3;url=ryxx.jsp\">");
}else if(type.equals("update"))
{//执行修改
String sql="select * from ryxx where ryid="+ryid;
ResultSet rs=open.ExecuteQuery(sql);
while(rs.next()){
%>
<form method="post" action=./ryxxedit.jsp>
<table align=center width=500 border=1 bordercolor=blue>
<tr><td colspan=2 align=center>人员修改
<input type=hidden name=type value=update>
<input type=hidden name=ryid value=<%=ryid%>></td></tr>
<tr><td width=100>姓名</td><td><input type=text name=ryxm value=<%=rs.getString(2)%>></td></tr>
<%if(rs.getString(3).equals("男")){%>
<tr><td>性别</td><td><input type=radio name=ryxb value="男" checked>男<input type=radio name=ryxb value="女">女</td></tr>
<%}else{%>
<tr><td>性别</td><td><input type=radio name=ryxb value="男">男<input type=radio name=ryxb value="女" checked>女</td></tr>
<%}%>
<tr><td>年龄</td><td><input name=nl value=<%=rs.getInt(4)%>></td></tr>
<tr><td>班级</td><td><input type=text name=bjbh value=<%=rs.getInt(5)%>></td></tr>
<tr><td colspan=2 align=center>
<input type="submit" name="Submit" value="保存">
<input type="reset" value="重填"></td></tr>
</table>
</form>
<p align=right><a hrer="#" onClick="history.back(1)">返回</a></p>
<%
}
}
%>

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧