📄 databaseutil.java
字号:
package com.guestbook.sys;
import java.sql.*;
import java.util.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class DataBaseUtil
{
private static final Log logger = LogFactory.getLog(DataBaseUtil.class);
private DataBaseUtil()
{
}
public static boolean ExecuteSQL( String sql )
{
Connection conn = null;
Statement stmt = null;
try
{
conn = DataBaseConnection.getConnection();
stmt = conn.createStatement();
stmt.executeUpdate( sql );
return true;
}
catch( Exception exp )
{
return false;
}
finally
{
try
{
stmt.close();
conn.close();
}
catch( Exception exp )
{
logger.error( exp );
}
}
}
public static Vector getDataTable( String sql )
{
Connection conn = null;
Statement stmt = null;
try
{
conn = DataBaseConnection.getConnection();
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
Vector dataTable = getDataTable( rs );
rs.close();
stmt.close();
conn.close();
return dataTable;
}
catch( Exception exp )
{
logger.error( exp );
return null;
}
}
public static Vector getDataTable( ResultSet rs ) throws SQLException
{
Vector dataTable = new Vector( 30 );
ResultSetMetaData rsmd=rs.getMetaData();
while( rs.next() )
{
Vector item = new Vector( 10 );
for( int i = 1 ; i <= rsmd.getColumnCount() ; i++ )
{
if( rsmd.getColumnTypeName( i ).equals( "CLOB" ) )
{
Clob colClob = rs.getClob( i );
if( colClob == null )
{
item.add( "" );
}
else
{
item.add( getClobtoString( rs.getClob( i ) ) );
}
}
else
{
item.add( rs.getObject( i ) );
}
}
dataTable.add( item );
}
return dataTable;
}
private static String getClobtoString( Clob clob ) throws SQLException
{
return clob.getSubString(((long)1),((int)(clob.length())));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -