datasource.driverClassName=oracle.jdbc.driver.OracleDriver
datasource.url=jdbc:oracle:thin:@10.6.1.11:1521:student
datasource.username=zs
datasource.password=zs
datasource.defaultAutoCommit=true
hibernate.dialect=org.hibernate.dialect.Oracle9Dialect
#当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3
c3p0.acquireIncrement=5
#初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3
c3p0.initialPoolSize=10
#每60秒检查所有连接池中的空闲连接。Default: 0
c3p0.idleConnectionTestPeriod=600
#-连接池中保留的最小连接数。
c3p0.minPoolSize=5
#连接池中保留的最大连接数。Default: 15
c3p0.maxPoolSize=50
#JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements
#属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。
#如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0
c3p0.maxStatements=100
#c3p0是异步 *** 作的,缓慢的JDBC *** 作通过帮助进程完成。扩展这些 *** 作可以有效的提升性能
#通过多线程实现多个 *** 作同时被执行。Default: 3
c3p0.numHelperThreads=10
#最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0
c3p0.maxIdleTime=600
#hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.jdbc.batch_size=25
hibernate.jdbc.fetch_size=50
hibernate.show_sql=true
hibernate.connection.release_mode=after_transaction
2. 其次是spring配置文件的数据源配置:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/classes/conf/jdbc/jdbc.properties</value>
</property>
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" dependency-check="none">
<property name="driverClass">
<value>${datasource.driverClassName}</value>
</property>
<property name="jdbcUrl">
<value>${datasource.url}</value>
</property>
<property name="user">
<value>${datasource.username}</value>
</property>
<property name="password">
<value>${datasource.password}</value>
</property>
<!-- 当连接池中连接耗尽的时候c3p0一次同时获取的连接数 -->
<property name="acquireIncrement">
<value>${c3p0.acquireIncrement}</value>
</property>
<!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
<property name="initialPoolSize">
<value>${c3p0.initialPoolSize}</value>
</property>
<!-- 最小连接数 -->
<property name="minPoolSize">
<value>${c3p0.minPoolSize}</value>
</property>
<!-- 最大连接数 -->
<property name="maxPoolSize">
<value>${c3p0.minPoolSize}</value>
</property>
<!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime">
<value>${c3p0.maxPoolSize}</value>
</property>
<!--每60秒检查所有连接池中的空闲连接。Default: 0 -->
<property name="idleConnectionTestPeriod">
<value>${c3p0.idleConnectionTestPeriod}</value>
</property>
<!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements属于单个connection而不是整个连接池。
所以设置这个参数需要考虑到多方面的因素。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0-->
<property name="maxStatements">
<value>${c3p0.maxStatements}</value>
</property>
<!--c3p0是异步 *** 作的,缓慢的JDBC *** 作通过帮助进程完成。扩展这些 *** 作可以有效的提升性能通过多线程实现多个 *** 作同时被执行。Default: 3-->
<property name="numHelperThreads">
//动态库和普通进程调用数据库方式没有任何区别,以下的程序兼容WINDOWS ODBC数据库连接和LINUX MYSQL连接,是跨平台的。#ifdef WIN32
#include <windows.h>
#include <odbcinst.h>
#include <sqlext.h>
#else
#include <mysql.h>
#include <unistd.h>
#define SQLHANDLE static MYSQL
#endif
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
SQLHANDLE hDBEnv, hDBC
int DB_Open(char * dbcn, char * usr, char * pwd)
{
int r
#ifdef WIN32
r = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hDBEnv)
if(r) return 0
r = SQLSetEnvAttr(hDBEnv,SQL_ATTR_ODBC_VERSION,
(void*)SQL_OV_ODBC3,0)
if(r) return 0
r = SQLAllocHandle(SQL_HANDLE_DBC, hDBEnv, &hDBC)
if(r) return 0
r = SQLConnect(hDBC,
(unsigned char *)dbcn, strlen(dbcn),
(unsigned char *)usr, strlen(usr),
(unsigned char *)pwd, strlen(pwd))
return r==SQL_SUCCESS || r==SQL_SUCCESS_WITH_INFO
#else
mysql_init(&hDBC)
MYSQL * rx = mysql_real_connect(
&hDBC, dbcn, usr, pwd, NULL, 0, NULL, 0)
if(!rx) return 0
return 1
#endif
}//end DB_Open
int DB_Exec(char * sql)
{
#ifdef WIN32
SQLHANDLE hStatement = NULL
SQLAllocHandle(SQL_HANDLE_STMT, hDBC, &hStatement)
SQLExecDirect(hStatement,(unsigned char *)sql, strlen(sql))
SQLCloseCursor(hStatement)
SQLFreeHandle(SQL_HANDLE_STMT, hStatement)
hStatement = NULL
#else
mysql_real_query (&hDBC, sql, strlen(sql))
#endif
return 1
}//end DB_Exec
int DB_Close(void)
{
#ifdef WIN32
SQLDisconnect(hDBC)
SQLFreeHandle(SQL_HANDLE_DBC, hDBC)
SQLFreeHandle(SQL_HANDLE_ENV, hDBEnv)
#else
mysql_close(&hDBC)
#endif
return 1
}//DB_Close()
#ifndef WIN32
typedef struct tagMySQLRecordset {
MYSQL_RES * hRecord
void * * row
int * size
int cols
} MYSQLRecordset
#endif
void DB_CleanQuery(void *hRecordset)
{
if(!hRecordset) return
#ifdef WIN32
__try {
SQLCloseCursor(hRecordset)
SQLFreeHandle(SQL_HANDLE_STMT, hRecordset)
hRecordset = NULL
}__finally{
return
}//end try
#else
MYSQLRecordset * hRec = (MYSQLRecordset *) hRecordset
mysql_free_result (hRec->hRecord)
free(hRec->row) hRec->row = NULL
free(hRec->size)hRec->size = NULL
free(hRec)hRec = NULL
#endif
}//end DB_CleanQuery
int DB_Next(void * hRecordset)
{
int r=0if(!hRecordset) return 0
#ifdef WIN32
r = SQLFetch(hRecordset)
r = r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO
if(!r) {
DB_CleanQuery(hRecordset)
}//end if
#else
MYSQLRecordset * hRec = (MYSQLRecordset *) hRecordset
MYSQL_ROW row = mysql_fetch_row (hRec->hRecord)
if(row) {
for(int i=0i<hRec->colsi++) {
memcpy(hRec->row[i], row[i], hRec->size[i])
}//next i
r = 1
}else{
DB_CleanQuery(hRecordset)
r = 0
}//end if
#endif
return r
}//end DB_Next
int DB_params_count(const char * fmt)
{
int i=0, j=0
while(fmt[i]) {
if(fmt[i]=='%') j++
i++
}//end while
return j
}//end DB_params_count
void * DB_Query(char *sql, const char *fmt, ...)
{
int r=0
int cols = DB_params_count(fmt)
if(cols<1) return NULL
#ifdef WIN32
SQLHANDLE hStatement = NULL
SQLAllocHandle(SQL_HANDLE_STMT, hDBC, &hStatement)
r = SQLExecDirect(hStatement,(unsigned char *)sql, strlen(sql))
r = r==SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO
if(!r) {
return NULL
}//end if
#else
r = mysql_real_query (&hDBC, sql, strlen(sql))
if(r) return NULL
MYSQL_RES * rec = NULL
rec = mysql_store_result (&hDBC)
if(!rec) return NULL
MYSQLRecordset * hStatement
= (MYSQLRecordset *)malloc(sizeof(MYSQLRecordset))
if(!hStatement) return NULL
memset(hStatement, 0, sizeof(MYSQLRecordset))
hStatement->hRecord = rec
hStatement->cols = cols
hStatement->row = (void **)malloc(cols * sizeof(void *))
memset(hStatement->row, 0, cols * sizeof(void *))
hStatement->size = (int *)malloc(cols * sizeof(int))
memset(hStatement->size, 0, cols * sizeof(int))
#endif
va_list apva_start(ap, fmt)
void * varchar buf[32]
int i=0,j=0,k=0,sz=0char c=0
int len = strlen(fmt)int bad=1
#ifdef WIN32
int col=1
#else
int col=0
#endif
while(fmt[i]) {
c = fmt[i++]
if(c != '%') continue
c = fmt[i++]
var = va_arg(ap, void *)
if(c == 'd') {
#ifdef WIN32
SQLBindCol(hStatement, col, SQL_C_SLONG, var, 4,NULL)
#else
hStatement->row[col] = var
hStatement->size[col] = sizeof(long)
#endif
col++
continue
}//end if
if(c == 'f') {
#ifdef WIN32
SQLBindCol(hStatement, col, SQL_C_FLOAT, var, 4,NULL)
#else
hStatement->row[col] = var
hStatement->size[col] = sizeof(float)
#endif
col++
continue
}//end if
memset(buf, 0, 32)bad=1
for(j=i-1j<lenj++) {
c = fmt[j]
if(c>='0' &&c<='9') buf[j-i+1]=c
if(c=='s')
}//next j
if(bad) return NULL
sscanf(buf, "%d", &sz)
#ifdef WIN32
SQLBindCol(hStatement, col, SQL_C_CHAR, var, sz, NULL)
#else
hStatement->row[col] = var
hStatement->size[col] = sz
#endif
col++
i = k
}//end while
va_end(ap)
return hStatement
}//end DB_Rec
我可以帮助你,你先设置我最佳答案后,我百度Hii教你。
那不是代码的问题,是php的配置文件的错误报告引起的。error_reporting(E_ALL
^
E_NOTICE)会显示所有的错误报告,
可以考虑用
//
Turn
off
all
error
reporting
error_reporting(0)
或
//
Report
simple
running
errors
error_reporting(E_ERROR
|
E_WARNING
|
E_PARSE)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)