当前位置: 首页>>代码示例>>Java>>正文


Java ComboPooledDataSource.getConnection方法代码示例

本文整理汇总了Java中com.mchange.v2.c3p0.ComboPooledDataSource.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java ComboPooledDataSource.getConnection方法的具体用法?Java ComboPooledDataSource.getConnection怎么用?Java ComboPooledDataSource.getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mchange.v2.c3p0.ComboPooledDataSource的用法示例。


在下文中一共展示了ComboPooledDataSource.getConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
@Override
public void run() {
	ComboPooledDataSource cpds = new ComboPooledDataSource("postgres");
	try {
		Date start = new Date();
		Connection conn = cpds.getConnection();
		conn.setAutoCommit(false);
		PreparedStatement ps = conn
				.prepareStatement("insert into measurement(field1,field2,field3,field4,field5,field6,field7) values(?,?,?,?,?,?,?)");
		int m = 1;
		System.out.println(Lock.isComeOn.get());
		while (Lock.isComeOn.get()) {
			buffer.take().write(ps);
			m++;
			if (m % 1000 == 0) {
				ps.executeBatch();
				conn.commit();
			}
		}
		Date end = new Date();
		System.out.println("WriteThread:" + Thread.currentThread().getName()
				+ " Over with time:" + (end.getTime() - start.getTime()) / 1000);// �����
	} catch (SQLException | InterruptedException e) {
		e.printStackTrace();
	}
}
 
开发者ID:chenzhenyang,项目名称:aquila,代码行数:27,代码来源:WriteThread.java

示例2: writeTest

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public static void writeTest(){
		try {
			ComboPooledDataSource cpds = new ComboPooledDataSource();
			Connection conn = cpds.getConnection();
			PreparedStatement ps = conn.prepareStatement("insert into OtherTest1(field1) values(?)");
			for (int i = 0; i < 100; i++) {
				SQLXML sqlxml = conn.createSQLXML();
				sqlxml.setString("<t>m</t>");
				ps.setSQLXML(1, sqlxml );
//				ps.setString(1, "<test>"+i+"</test>");  //xml = String
				ps.execute();
			}
			ps.close();
			conn.close();
			cpds.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
 
开发者ID:chenzhenyang,项目名称:aquila,代码行数:20,代码来源:TestOtherXML.java

示例3: getConnection

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
/**
 *
 *
 * @param scenario
 * @return
 *
 * @throws SQLException
 */
public synchronized Connection getConnection(Scenario scenario) throws SQLException {
  Connection connection = null;
  if (scenario != null) {
    if (pools.containsKey(scenario)) {
      try {
        ComboPooledDataSource pool = pools.get(scenario);
        connection = pool.getConnection();
        connection.setCatalog(scenario.getDbName());
      } catch (Exception exception) {
        errors.put(scenario, exception.getMessage());
        throw exception;
      }
    }
  }
  return connection;
}
 
开发者ID:UniversityOfWuerzburg-ChairCompSciVI,项目名称:ueps,代码行数:25,代码来源:ConnectionManager.java

示例4: writeTest

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public static void writeTest() {
	try {
		ComboPooledDataSource cpds = new ComboPooledDataSource("postgres");
		Connection conn = cpds.getConnection();
		PreparedStatement ps = conn
				.prepareStatement("insert into transfertestclob(field1,field2,field3,field4) values(XML(?),?,?,?)");
		for (int i = 0; i < list.size(); i++) {
			list.get(i).write(ps);
			ps.execute();
		}

		ps.close();
		conn.close();
		cpds.close();
	} catch (SQLException e) {
		e.printStackTrace();
	}
}
 
开发者ID:chenzhenyang,项目名称:aquila,代码行数:19,代码来源:TestClob.java

示例5: writeTest

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public static void writeTest() {
	try {
		ComboPooledDataSource cpds = new ComboPooledDataSource("postgres");
		Connection conn = cpds.getConnection();
		PreparedStatement ps = conn
				.prepareStatement("insert into transferdatetimetest(field1,field2,field3,field4,field5,field6) values(?,?,?,?,?,?)");
		for (int i = 0; i < list.size(); i++) {
			list.get(i).write(ps);
			ps.execute();
		}

		ps.close();
		conn.close();
		cpds.close();
	} catch (SQLException e) {
		e.printStackTrace();
	}
}
 
开发者ID:chenzhenyang,项目名称:aquila,代码行数:19,代码来源:TestDatetime.java

示例6: writeTest

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public static void writeTest() {
	try {
		ComboPooledDataSource cpds = new ComboPooledDataSource("postgres");
		Connection conn = cpds.getConnection();
		PreparedStatement ps = conn
				.prepareStatement("insert into testuuid(field1) values(?)");
		for (int i = 0; i < 1; i++) {
			ps.setBytes(1, "A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11".getBytes());
			ps.execute(); 
		}
		ps.close();
		conn.close();
		cpds.close();
	} catch (SQLException e) {
		e.printStackTrace();
	}
}
 
开发者ID:chenzhenyang,项目名称:aquila,代码行数:18,代码来源:TestUUID.java

示例7: call

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
@Override
public ObjectValue<Connection> call(XPathContext context, Sequence[] arguments) throws XPathException {            
  try {
    String name = ((StringValue) arguments[0].head()).getStringValue();        
    String userName = null;
    String password = null;
    Boolean readOnly = null;
    Boolean autoCommit = null; 
    if (arguments.length > 1) {
      userName = ((StringValue) arguments[1].head()).getStringValue(); 
    }
    if (arguments.length > 2) {
      password = ((StringValue) arguments[2].head()).getStringValue();
    }
    if (arguments.length > 3) {
      readOnly = ((BooleanValue) arguments[3].head()).getBooleanValue();
    }
    if (arguments.length > 4) {
      autoCommit = ((BooleanValue) arguments[4].head()).getBooleanValue();
    }
    WebApp webapp = getWebApp(context);
    ComboPooledDataSource dataSource = webapp.getDataSource(name);        
    Connection connection;
    if (StringUtils.isNotBlank(userName)) {
      connection = dataSource.getConnection(userName, password);
    } else {
      connection = dataSource.getConnection();
    }        
    if (readOnly != null) {
      connection.setReadOnly(readOnly.booleanValue());
    }
    if (autoCommit != null) {
      connection.setAutoCommit(autoCommit.booleanValue());
    }          
    addCloseable(new CloseableAutoCloseableWrapper(connection), context);                        
    return new ObjectValue<Connection>(connection);        
  } catch (Exception e) {
    throw new XPathException("Could not create connection", e);
  }
}
 
开发者ID:Armatiek,项目名称:xslweb,代码行数:41,代码来源:GetConnection.java

示例8: writeTest

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public static void writeTest() {
		try {
			ComboPooledDataSource cpds = new ComboPooledDataSource("postgres");
			Connection conn = cpds.getConnection();
			PreparedStatement ps = conn
					.prepareStatement("insert into testdatatime2(field1,field2,field3) values(?,?,?)");
			for (int i = 0; i < 100; i++) {
				/**
				 * ���ֿ���
				 */
//				ps.setTimestamp(1, new Timestamp(i)); // date = date
//				ps.setDate(2, new Date(i)); // datetimeoffset = timestamp
//				ps.setTime(3, new Time(i)); // time = time
				
				/**
				 * ���ֿ���
				 */
//				ps.setObject(1, new Timestamp(i));
//				ps.setObject(2, new Date(i));
//				ps.setObject(3, new Time(i));
				
				 
				ps.setObject(1, new Timestamp(i), Types.TIMESTAMP);
				ps.setObject(2, new Date(i), Types.DATE);
				ps.setObject(3, new Time(i), Types.TIME);
				
				ps.execute();
			}
			ps.close();
			conn.close();
			cpds.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
 
开发者ID:chenzhenyang,项目名称:aquila,代码行数:36,代码来源:TestDate.java

示例9: run

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
@Override
public void run() {
	ComboPooledDataSource cpds = new ComboPooledDataSource();
	try {
		Date start = new Date();
		Connection conn = cpds.getConnection();
		conn.setAutoCommit(false);
		PreparedStatement ps = conn.prepareStatement("insert into measurement2(field1,field2,field3,field4,field5,field6,field7) values(?,?,?,?,?,?,?)");
		int m = 1;
		for (int i = 0; i < InsertTask.SUM; i++) {
			ps.setString(1, "field1-" + i);
			ps.setString(2, "field2-" + i);
			ps.setString(3, "field3-" + i);
			ps.setString(4, "field4-" + i);
			ps.setString(5, "field5-" + i);
			ps.setString(6, "field6-" + i);
			ps.setString(7, "field7-" + i);
			ps.addBatch();
			m++;
			if (m % 50 == 0) {
				m = 1;
				ps.executeBatch();
				conn.commit();
			}
		}
		Date end = new Date();
		System.out.println((end.getTime() - start.getTime()) / 1000);// �����
	} catch (SQLException e) {
		e.printStackTrace();
	}
}
 
开发者ID:chenzhenyang,项目名称:aquila,代码行数:32,代码来源:MuitleThreadWriter.java

示例10: main

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public static void main(String[] args) {
	ComboPooledDataSource cpds = new ComboPooledDataSource("postgres");
	Connection conn = null;
	try {
		conn = cpds.getConnection();
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
开发者ID:chenzhenyang,项目名称:aquila,代码行数:12,代码来源:TestRemoteConnection.java

示例11: readTest

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public static void readTest() {
		try {
			ComboPooledDataSource cpds = new ComboPooledDataSource();
			Connection conn = cpds.getConnection();
			PreparedStatement ps = conn.prepareStatement("select * from  PreciseNumberTest");
			ResultSet rs = ps.executeQuery();
			
			ResultSetMetaData rsmd = rs.getMetaData();
			int columnCount = rsmd.getColumnCount();
			for(int m = 1 ;m <= columnCount; m++){
				String columnName = rsmd.getColumnName(m);
				String columntype = rsmd.getColumnTypeName(m);
				int columntypen = rsmd.getColumnType(m);
				System.out.println(columnName + ":" +columntype+":"+columntypen);
			}
			
			
//			int i = 0;
//			while (rs.next()) {
//				long field0 = rs.getLong(1);
//				double field1 = rs.getDouble(2);
//				byte field2 = rs.getByte(3);
//				short field3 = rs.getShort(4);
//				double field4 = rs.getDouble(5);
//				float field5 = rs.getFloat(6);
//				int field6 = rs.getInt(7);
//				short field7 = rs.getShort(8);
//				double field8 = rs.getDouble(9);
//				System.out.println("record" + i++ + ":field0=" + field0 + ":field1=" + field1 + ":field2=" + field2
//						+ ":field3=" + field3 + ":field4=" + field4 + ":field5=" + field5 + ":field6=" + field6
//						+ ":field7=" + field7 + ":field8=" + field8);
//			}
			rs.close();
			ps.close();
			conn.close();
			cpds.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
 
开发者ID:chenzhenyang,项目名称:aquila,代码行数:41,代码来源:TestPreciseNumber.java

示例12: readTest

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public static void readTest() {
		try {
			ComboPooledDataSource cpds = new ComboPooledDataSource("postgres");
			Connection conn = cpds.getConnection();
			PreparedStatement ps = conn.prepareStatement("select * from  testxml");
			ResultSet rs = ps.executeQuery();

			ResultSetMetaData rsmd = rs.getMetaData();
			int columnCount = rsmd.getColumnCount();
			for(int m = 1 ;m <= columnCount; m++){
				String columnName = rsmd.getColumnName(m);
				String columntype = rsmd.getColumnTypeName(m);
				int columntypen = rsmd.getColumnType(m);
				System.out.println(columnName + ":" +columntype+":"+columntypen);
			}
			
			int i = 0;
			while (rs.next()) {
//				String field1 = rs.getString(1);  //okay
//				SQLXML field1 = rs.getSQLXML(1);  //xml����ר�ŵĽӿڣ���Ȼ����
				
				/**
				 * ֱ����getSQLXML���У������ÿ��ԣ���getObject��Ȼ��ת��
				 */
				Object field1 = rs.getObject(1);
				SQLXML sqlxml = (Jdbc4SQLXML)field1;
				String str = sqlxml.getString();
				System.out.println(field1.getClass().getName());
				
				System.out.println("record" + i++ + ":field1=" + str);
			}
			
			rs.close();
			ps.close();
			conn.close();
			cpds.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
 
开发者ID:chenzhenyang,项目名称:aquila,代码行数:41,代码来源:TestXML.java

示例13: obtainConnection

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
protected Connection obtainConnection(ComboPooledDataSource cpds) throws ConnectException {
    Connection connection;
    try {
        connection = cpds.getConnection();
    } catch (SQLException e) {
        throw new ConnectException("Cannot obtain sql connection", e);
    }

    registerConnectionInUse(connection);
    return connection;
}
 
开发者ID:ventilb,项目名称:stagediver.fx-database,代码行数:12,代码来源:ConnectionServiceImpl.java

示例14: readTest

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public static void readTest() {
		try {
			ComboPooledDataSource cpds = new ComboPooledDataSource();
			Connection conn = cpds.getConnection();
			PreparedStatement ps = conn.prepareStatement("select * from  OtherTest4");
			ResultSet rs = ps.executeQuery();
			
			ResultSetMetaData rsmd = rs.getMetaData();
			int columnCount = rsmd.getColumnCount();
			for(int m = 1 ;m <= columnCount; m++){
				String columnName = rsmd.getColumnName(m);
				String columntype = rsmd.getColumnTypeName(m);
				int columntypen = rsmd.getColumnType(m);
				System.out.println(columnName + ":" +columntype+":"+columntypen);
			}
			
//			int i = 0;
//			while (rs.next()) {
//				String field1 = rs.getString(1);  
//				String field2 = rs.getString(2);
//				System.out.println("record" + i++ + ":field1=" + field1 + ":field1=" + field2);
//			}
			rs.close();
			ps.close();
			conn.close();
			cpds.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
 
开发者ID:chenzhenyang,项目名称:aquila,代码行数:31,代码来源:TestOther4.java

示例15: readTest

import com.mchange.v2.c3p0.ComboPooledDataSource; //导入方法依赖的package包/类
public static void readTest() {
		try {
			ComboPooledDataSource cpds = new ComboPooledDataSource();
			Connection conn = cpds.getConnection();
			PreparedStatement ps = conn.prepareStatement("select * from  StringTest");
			ResultSet rs = ps.executeQuery();
			
			ResultSetMetaData rsmd = rs.getMetaData();
			int columnCount = rsmd.getColumnCount();
			for(int m = 1 ;m <= columnCount; m++){
				String columnName = rsmd.getColumnName(m);
				String columntype = rsmd.getColumnTypeName(m);
				int columntypen = rsmd.getColumnType(m);
				System.out.println(columnName + ":" +columntype+":"+columntypen);
			}
			
			
//			int i = 0;
//			while (rs.next()) {
//				String field1 = rs.getString(1);
//				String field2 = rs.getString(2);
//				String field3 = rs.getString(3);
//				System.out.println("record" + i++ + ":field1=" + field1 + " field2=" + field2 + " field3=" + field3);
//			}
			rs.close();
			ps.close();
			conn.close();
			cpds.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
 
开发者ID:chenzhenyang,项目名称:aquila,代码行数:33,代码来源:TestString.java


注:本文中的com.mchange.v2.c3p0.ComboPooledDataSource.getConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。