论坛首页 入门技术论坛

apache ddlutil crud

浏览 1957 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-10-22  
package test;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Iterator;


import oracle.jdbc.pool.OracleDataSource;

import org.apache.commons.beanutils.DynaBean;
import org.apache.ddlutils.Platform;
import org.apache.ddlutils.PlatformFactory;
import org.apache.ddlutils.io.DatabaseIO;
import org.apache.ddlutils.model.Database;
import org.apache.ddlutils.model.Table;
import org.apache.ddlutils.platform.oracle.Oracle10Platform;

public class T {

//	create table ASK_USERPOINT
//	(
//	  USERNAME VARCHAR2(20) not null,(主键)
//	  POINT    NUMBER(20) default 1000
//	)
	public static void main(String[] args) throws SQLException {
		OracleDataSource dataSource=new OracleDataSource();
		dataSource.setURL("jdbc:oracle:thin:@192.168.1.211:1521:bky");
		dataSource.setUser("scott");
		dataSource.setPassword("tiger");
		Platform platform = PlatformFactory.createNewPlatformInstance(Oracle10Platform.DATABASENAME);
		platform.setDataSource(dataSource);
		
		
		Database database =platform.readModelFromDatabase("bky",null,"SCOTT",null);
		//-----------查询
//		Iterator it = platform.query(database, "SELECT * FROM ASK_QUESTION",
//				new Table[] { database.findTable("ASK_QUESTION")});
//		while (it.hasNext()) {
//			DynaBean book = (DynaBean) it.next();
//			System.out.println(book.get("TIME"));
//		}
		//----------插入
//		DynaBean ask_userpoint = database.createDynaBeanFor("ASK_USERPOINT", false);
//		ask_userpoint.set("USERNAME", "gao12");
//		ask_userpoint.set("POINT", 100L);
//		platform.insert(database, ask_userpoint);
		
		//----------更新
//		DynaBean ask_userpoint = database.createDynaBeanFor("ASK_USERPOINT", false);
//		ask_userpoint.set("USERNAME", "gao11");
//		ask_userpoint.set("POINT", 200L);
//		platform.update(database, ask_userpoint);
		//----------删除
//		DynaBean ask_userpoint = database.createDynaBeanFor("ASK_USERPOINT", false);
//		ask_userpoint.set("USERNAME", "gao11");
//		platform.delete(database, ask_userpoint) ;
		
		//----------把数据库写如文件
	new DatabaseIO().write(database,"D:\\aaaa.xml" );
		//----------从文件读取数据库
//		Database tets=new DatabaseIO().read("D:\\A.txt");
		
		DynaBean dynaBean = database.createDynaBeanFor("ASK_USERPOINT", false);
		String delSql=platform.getDeleteSql(database, dynaBean);
		System.out.println(delSql);
		String inSql=platform.getInsertSql(database, dynaBean);
		System.out.println(inSql);
		String upSql=platform.getUpdateSql(database, dynaBean);
		System.out.println(upSql);
	
	
		
		

	}

}

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics