4 public class SqlException : Exception{
8 public SqlException(int err, String sqlmessage){
14 public class DatabaseNotSupportException : SqlException{
17 message =
"not support method:" + sqlmessage;
21 public interface ConnPoolCallback{
35 static const int TIMEOU_LIMIT = 300000;
45 Connection
connector = callback.createConnection();
57 if (_maxConnect != 0){
58 while ((_pool.
size() == 0) && (_active_cnt >= _maxConnect)){
85 if ((_maxConnect == 0) || (_active_cnt < _maxConnect)){
95 return callback.alive(
conn);
110 if (_maxIdleTime != 0){
117 if ((
mgr.timestamp -
pmt.timestamp) > _maxIdleTime){
118 pmt.pconnection.close();
129 while (_pool.
size() > _maxIdle){
132 pmt.pconnection.close();
177 for (
int i = 0;
i <
elist.length;
i++){
180 _error_map.
put(
str.parseInt(),
true);
202 _maxIdleTime = TIMEOU_LIMIT;
211 synchronized(_database){
221 synchronized(_database){
239 public interface Connection{
301 public interface Statement{
315 public static class PreparedStatement : Statement{
323 textSql =
" " + sql +
" ";
324 strsplit = textSql.
split(
'?');
325 if (strsplit.
length == 0){
328 strparams =
new String[strsplit.length - 1];
332 str = str.
replace(
"\\",
"\\\\");
333 str = str.
replace(
"\"",
"\\\"");
334 str = str.
replace(
"\'",
"\\\'");
335 str = str.
replace(
"\`",
"\\\`");
336 return "'" + str +
"'";
340 return execute(getSql());
344 String sqlout = strsplit[0];
345 int i = 1, c = strsplit.
length;
347 sqlout = sqlout + (strparams[i - 1] + strsplit[i]);
353 return executeQuery(getSql());
357 return executeUpdate(getSql());
361 if (paramid < strparams.
length){
362 strparams[paramid++] = safety(value);
364 throw new SqlException(-1,
"sql " +textSql +
" dont need value:" + value);
369 if (paramid < strparams.
length){
372 throw new SqlException(-1,
"sql " +textSql +
" dont need value:" + value);
377 if (paramid < strparams.
length){
380 throw new SqlException(-1,
"sql " +textSql +
" dont need value:" + value);
385 if (paramid < strparams.
length){
386 strparams[paramid++] =
String.
format(
"%02u",value & 0xff);
388 throw new SqlException(-1,
"sql " +textSql +
" dont need value:" + value);
393 if (paramid < strparams.
length){
396 throw new SqlException(-1,
"sql " +textSql +
" dont need value:" + value);
402 if ((
id > 0) && (
id - 1 < strparams.
length)){
403 strparams[
id - 1] = safety(value);
405 throw new SqlException(-1,
"sql " +textSql +
" dont need value:" + value);
410 if ((
id > 0) && (
id - 1 < strparams.
length)){
413 throw new SqlException(-1,
"sql " +textSql +
" dont need value:" + value);
418 if ((
id > 0) && (
id - 1 < strparams.
length)){
421 throw new SqlException(-1,
"sql " +textSql +
" dont need value:" + value);
426 if ((
id > 0) && (
id - 1 < strparams.
length)){
429 throw new SqlException(-1,
"sql " +textSql +
" dont need value:" + value);
434 if ((
id > 0) && (
id - 1 < strparams.
length)){
437 throw new SqlException(-1,
"sql " +textSql +
" dont need value:" + value);
442 for (
int i = 0; i < args.length; i++){
443 if (args[i].instanceOf(
String)){
444 setValue((
String)args[i]);
446 if (args[i].instanceOf(
int)){
447 setValue((
int)args[i]);
449 if (args[i].instanceOf(
long)){
450 setValue((
long)args[i]);
452 if (args[i].instanceOf(
byte)){
453 setValue((
byte)args[i]);
455 if (args[i].instanceOf(
double)){
456 setValue((
double)args[i]);
458 throw new SqlException(-1,
"sql " +textSql +
" dont accept type:" + i);
464 throw new SqlException(-1,
"get_changes");
static final long currentTimeMillis()
void recycle(Connection connection)
ConnPoolCallback callback
bool config(ConnPoolCallback _callback, String reset_error, int maxWait, int maxConnect, int maxIdle, int maxIdleTime, int validtesttime)
Connection getConnector()
bool test(Connection conn, long lastactive)
static bool reigstry(String name, ConnectionRegister reg)
static Connection getConnection(String driverName)
DatabaseNotSupportException(String sqlmessage)
int get_changes() override
void setValue(double value)
void setValue(byte value)
void setValue(int id, String value)
PreparedStatement(String sql)
void setValue(String value)
String safety(String str)
void setValue(int id, double value)
void setValue(int id, int value)
void setValue(int id, byte value)
void setValues(Object [] args)
void setValue(long value)
void setValue(int id, long value)
static final String format(String, Object[])
String replace(int, int, String)
Connection createConnection()
bool alive(Connection conn)
void setOption(int opt, Object option)
PreparedStatement prepareStatement(String sql)
Object getOption(int opt)
void create(String uri, String username, String pwd)
Statement createStatement()
Connection allocConnection(String drivername)
double getDouble(int columnIndex)
String getString(int columnIndex)
String getString(String columnlabel)
int getInt(int columnIndex)
bool getBoolean(String columnlabel)
int getInt(String columnlabel)
long getLong(String columnlabel)
long getLong(int columnIndex)
byte getByte(int columnIndex)
String getColumnName(int i)
byte getByte(String columnlabel)
double getDouble(String columnlabel)
bool getBoolean(int columnIndex)
int executeUpdate(String sql)
ResultSet executeQuery(String sql)