⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ibatissqlmapclient.java

📁 演示ibatis的基本使用方法
💻 JAVA
字号:
/*
 * 创建日期 2006-5-8
 *
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
package learnBasic;

import java.io.Reader;
import java.sql.SQLException;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class IBatisSqlMapClient {
	
	private static SqlMapClient IBDataMapper = null;
	
	public IBatisSqlMapClient(){
		
		loadResourceProp();
	}

	private static  void loadResourceProp() {
		Reader reader = null;
        try {
            reader = Resources.getResourceAsReader("learnBasic/sql-map-config.xml" );
            IBDataMapper = SqlMapClientBuilder.buildSqlMapClient( reader );
        } catch ( Exception e ) {
            e.printStackTrace();
        }
	}
	
	public static SqlMapClient getIBDataMapper(){
		
		if (IBDataMapper==null) loadResourceProp();
		return IBDataMapper;
	}
	
	
	public void SqlMapClient( SqlMapClient IBDataMapper ){
        try {
//            //Query for the sequence using "getSequence" as the
//            //Mapped Statement id, and where the name of the
//            //Sequence is "ProductSeq".
//            Sequence sequence = new Sequence( "ProductSeq", -1 );
//            sequence = (Sequence) dataMapper.queryForObject( "getSequence", sequence );
//
//            System.out.println( "-----" );
//            System.out.println( "Sequence Name: " + sequence.getSequenceName() );
//            System.out.println( "Next ID: " + sequence.getNextId() );
//
//            int nextId = sequence.getNextId();
//
//            //Update the sequence by incrementing the NEXT_ID
//            //column.
//            sequence.setNextId( sequence.getNextId() + 1 );
        	IBDataMapper.update( "updateSequence", null );
//
//            //Instantiate a new Product object with some random
//            //values...
//            Product product = new Product( nextId, "iBATIS Sandwich",
//                    "A Yummy Sandwich", 24 );
//
//            //Ask the dataMapper to insert the object for us into
//            //the database.
//            product = (Product) dataMapper.insert( "insertProduct", product );
//
//            Product queryProd = new Product();
//            queryProd.setProductId( nextId );
//
//            queryProd = (Product) dataMapper.queryForObject( "getProduct", queryProd );
//
//            System.out.println( "-----" );
//            System.out.println( "Product ID  : " + queryProd.getProductId() );
//            System.out.println( "Product Name: " + queryProd.getProductName() );
//            System.out.println( "Product Desc: " + queryProd.getProductDesc() );
//            System.out.println( "Product Qty : " + queryProd.getQuantity() );
//            System.out.println( "-----" );
//
            System.out.println( "Yay, that was fun." );
        } catch (SQLException e ) {
            e.printStackTrace();
        }
    }
	
	public static void main( String[] args ) {
        new IBatisSqlMapClient().SqlMapClient( IBDataMapper );
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -