c3p0 快速入门测试

package com.gyarmy.c3p0;


import java.sql.Connection;
import java.sql.PreparedStatement;

import org.junit.Test;

import com.gyramy.utils.JdbcUtils;
import com.mchange.v2.c3p0.*;

public class C3P0Test {
	
	@Test
	public void test2(){
		
		Connection conn =null;
		PreparedStatement stmt = null;
		try {
			ComboPooledDataSource cpds = new ComboPooledDataSource();
			 conn = cpds.getConnection();
			 System.out.println(conn);
			 
			 stmt = conn.prepareStatement("update account set money=? where name=? ");
			 stmt.setDouble(1, 111111);
			 stmt.setString(2, "cc");
			 stmt.executeUpdate();
			
			 
			 System.err.println("www.baidu.com");
			 
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			
			JdbcUtils.release(null, stmt, conn);
		}   
		
	}
	
	
	
	@Test
	public void test1(){
		
		
		Connection conn =null;
		PreparedStatement stmt = null;
		try {
			ComboPooledDataSource cpds = new ComboPooledDataSource();
			cpds.setDriverClass( "com.mysql.jdbc.Driver" ); //loads the jdbc driver            
			cpds.setJdbcUrl( "jdbc:mysql:///test003" );
			cpds.setUser("root");                                  
			cpds.setPassword("abc");
			
			 conn = cpds.getConnection();
			 stmt = conn.prepareStatement("update account set money=? where name=? ");
			 stmt.setDouble(1, 666);
			 stmt.setString(2, "aa");
			 stmt.executeUpdate();
			
			 
			 System.err.println("www.baidu.com");
			 
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			
			JdbcUtils.release(null, stmt, conn);
		}        
		
		
	}
}

原文链接: c3p0 快速入门测试 版权所有,转载时请注明出处,违者必究。
注明出处格式:流沙团 ( https://gyarmy.com/post-76.html )

发表评论

0则评论给“c3p0 快速入门测试”