本文整理匯總了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();
}
}
示例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();
}
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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();
}
}
示例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();
}
}