spring数据源配置
greenplum.jdbc.driverClassName=org.postgresql.Driver
greenplum.jdbc.password=username
greenplum.jdbc.url=jdbc:postgresql://10.27.116.31:5432/dbname
greenplum.jdbc.username=password
<!-- ========================= -->
<bean id="customerSingleViewDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>${greenplum.jdbc.driverClassName}</value></property>
<property name="url"><value>${greenplum.jdbc.url}</value></property>
<property name="username"><value>${greenplum.jdbc.username}</value></property>
<property name="password"><value>${greenplum.jdbc.password}</value></property>
<property name="initialSize" value="2"></property>
<property name="maxIdle" value="10"></property>
<property name="maxActive" value="20"></property>
<property name="maxWait" value="1000"></property>
<property name="testOnBorrow" value="true"></property>
<property name="testOnReturn" value="true"></property>
<property name="testWhileIdle" value="true"></property>
<property name="removeAbandoned" value="true"></property>
<property name="removeAbandonedTimeout" value="1000"></property>
<property name="logAbandoned" value="true"></property>
</bean>
原生jdbc连接
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class GPTest {
public static void main(String[] args) {
try {
Class.forName("org.postgresql.Driver");
Connection db = DriverManager.getConnection("jdbc:postgresql://10.27.116.31:5432/dbname","username","password");
Statement st = db.createStatement();
ResultSet rs = st.executeQuery("select * from vw_test limit 1 offset 0");
while (rs.next()) {
System.out.println(rs.getString(1));
}
rs.close();
st.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
本文介绍了如何使用 Spring 进行 Greenplum 数据库的数据源配置,并展示了通过原生 JDBC 连接 Greenplum 的示例代码。
1万+

被折叠的 条评论
为什么被折叠?



