當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。