采用powerdesigner 9.5 设计数据库,vb 利用其ole功能开发生成代码

萝卜波 产品经理  2004-12-28 12:12:20
// 想法,
//将数据库表和字段信息导出,生成数据库表到java代码的映射
//一些字段再设置“不能为空”“email”。。。校验,生成客户端js校验代码,和服务器端每个表校验java代码.....
//生成structs相关代码
//预期目的,...
//工作正在进行中,完善之后和大家分享

//本人广州,05毕业研究生,有招人的吗,期待伯乐
// 个人求职简历 http://www.maqh.com.cn/carrot
...全文
43 点赞 收藏 3
写回复
3 条回复
萝卜波 2004年12月28日
希望大家多多支持。
回复 点赞
萝卜波 2004年12月28日
//已经完成 生成代码例
package com.cainfo.test;
import java.sql.*;
import java.util.*;
import javax.servlet.http.*;
import org.apache.log4j.logger;
public class Customer
{
private static Logger logger = Logger.getLogger(db.Customer);

private double CUSNUM;
private int CUSNAME;
private String CUSADDR;
private String CUSACT;
private String CUSTEL;
private String CUSFAX;

//*************************************************
public void setCUSNUM(double CUSNUM)
{
this.CUSNUM = CUSNUM;
}

public double getCUSNUM() { return this.CUSNUM;}

//*************************************************
public void setCUSNAME(int CUSNAME)
{
this.CUSNAME = CUSNAME;
}

public int getCUSNAME() { return this.CUSNAME;}

//*************************************************
public void setCUSADDR(String CUSADDR)
{
this.CUSADDR = CUSADDR;
}

public String getCUSADDR() { return this.CUSADDR;}

//*************************************************
public void setCUSACT(String CUSACT)
{
this.CUSACT = CUSACT;
}

public String getCUSACT() { return this.CUSACT;}

//*************************************************
public void setCUSTEL(String CUSTEL)
{
this.CUSTEL = CUSTEL;
}

public String getCUSTEL() { return this.CUSTEL;}

//*************************************************
public void setCUSFAX(String CUSFAX)
{
this.CUSFAX = CUSFAX;
}

public String getCUSFAX() { return this.CUSFAX;}
public void setFieldValue(String fieldName,string value)
{
if(fieldName.equals("CUSNUM") && value != null && value.trim().length()>=1) { setCUSNUM(Double.parseDouble(value)); return; }
if(fieldName.equals("CUSNAME") && value != null && value.trim().length()>=1) { setCUSNAME(Integer.parseInt(value)); return; }
if(fieldName.equals("CUSADDR") && value != null) { setCUSADDR(value); return; }
if(fieldName.equals("CUSACT") && value != null) { setCUSACT(value); return; }
if(fieldName.equals("CUSTEL") && value != null) { setCUSTEL(value); return; }
if(fieldName.equals("CUSFAX") && value != null) { setCUSFAX(value); return; }
}

public String getFieldValue(String fieldName)
{
if(fieldName.equals("CUSNUM")) return ""+ getCUSNUM();
if(fieldName.equals("CUSNAME")) return ""+ getCUSNAME();
if(fieldName.equals("CUSADDR")) return ""+ getCUSADDR();
if(fieldName.equals("CUSACT")) return ""+ getCUSACT();
if(fieldName.equals("CUSTEL")) return ""+ getCUSTEL();
if(fieldName.equals("CUSFAX")) return ""+ getCUSFAX();
}


private PreparedStatement pstmt;
private Statement stmt;
private String condition = "";

public void appendCondition(String cond)
{
if(condition.equals(")) condition = " where " + cond;
else condition+= " and " + cond ;
}

public cleareCondition() { condition = "" ;}
private void sqlClose(PreparedStatement st)
{
try{ if(st!=null) st.close();} catch(Exception ignore){ }
}
private void sqlClose(Statement st)
{
try{ if(st!=null) st.close();} catch(Exception ignore){ }
}
private void sqlClose(ResultSet rs)
{
try{ if(rs!=null) rs.close();} catch(Exception ignore){ }
}
public void sqlClose(Connection con)
{
try{ if(st!=null) con.close();} catch(Exception ignore){ }
}

public void setTableValue(HttpServletRequest request)
{
String value = null;
value = request.getParameter("CUSNUM");
if(value!=null && value.trim().length()>=1) setCUSNUM(Double.parseDouble(value));
value = request.getParameter("CUSNAME");
if(value!=null && value.trim().length()>=1) setCUSNAME(Integer.parseInt(value));
value = request.getParameter("CUSADDR");
if(value!=null) setCUSADDR(value);
value = request.getParameter("CUSACT");
if(value!=null) setCUSACT(value);
value = request.getParameter("CUSTEL");
if(value!=null) setCUSTEL(value);
value = request.getParameter("CUSFAX");
if(value!=null) setCUSFAX(value);
}

public void insert(Connection connection) throws Exception
{
try {
pstmt = connection.prepareStatement( "INSERT INTO Customer(" +
"CUSNUM,"+
"CUSNAME,"+
"CUSADDR,"+
"CUSACT,"+
"CUSTEL,"+
"CUSFAX"+
") values(?,?,?,?,?,?)");
pstmt.setDouble( 1, CUSNUM);
pstmt.setInt( 2, CUSNAME);
pstmt.setString( 3, CUSADDR);
pstmt.setString( 4, CUSACT);
pstmt.setString( 5, CUSTEL);
pstmt.setString( 6, CUSFAX);
pstmt.execute( );
} catch (SQLException e) {
logger.warn("insert()失败! ",e);
throw e;
} finally { sqlClose(pstmt);}
}

public void update(Connection connection) throws Exception
{
try {
pstmt = connection.prepareStatement( "update Customerset " +
"CUSNUM= ?,"+
"CUSNAME= ?,"+
"CUSADDR= ?,"+
"CUSACT= ?,"+
"CUSTEL= ?,"+
"CUSFAX= ?" +
" " + condition);
pstmt.setDouble( 1, CUSNUM);
pstmt.setInt( 2, CUSNAME);
pstmt.setString( 3, CUSADDR);
pstmt.setString( 4, CUSACT);
pstmt.setString( 5, CUSTEL);
pstmt.setString( 6, CUSFAX);
} catch (SQLException e) {
logger.warn("insert()失败! ",e);
throw e;
} finally { sqlClose(pstmt);}
}
public ArrayList query(Connection connection) throws Exception
{
ArrayList alist = new ArrayList();
ResultSet rs = null;
try {
stmt=connection.createStatement();
String strSQL="SELECT * FROM Customer " + condition;
rs = stmt.executeQuery(strSQL);
while(rs.next()){
Customer obj=new Customer();
obj.setCUSNUM(rs.getdouble("CUSNUM"));
obj.setCUSNAME(rs.getint("CUSNAME"));
obj.setCUSADDR(rs.getString("CUSADDR"));
obj.setCUSACT(rs.getString("CUSACT"));
obj.setCUSTEL(rs.getString("CUSTEL"));
obj.setCUSFAX(rs.getString("CUSFAX"));
alist.add(obj)
}
}catch(SQLException e){
logger.warn("query()失败! ",e);
alist = null;
throw e;
}finally{
sqlClose(rs);
sqlClose(stmt);
}

return alist;
}

}
//-----Generate Database to java code by carrot zsu-----//
回复 点赞
sgdb 2004年12月28日
支持一下
回复 点赞
发动态
发帖子
Java EE
创建于2007-09-28

3.7w+

社区成员

22.5w+

社区内容

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区公告
暂无公告