当前位置: 技术问答>java相关
哪位大虾能给出一个通用的数据库处理bean,马上给分!
来源: 互联网 发布时间:2015-09-02
本文导语: 包括数据库连接,增/删/改/查(用PreparedStatement). | // // SourceAgain (TM) v1.10 (Core Java 1.2 Trial) // (C) 1998 Ahpah Software Inc // Please visit our website at http://www.ahpah.com for purchasing information. //...
包括数据库连接,增/删/改/查(用PreparedStatement).
|
//
// SourceAgain (TM) v1.10 (Core Java 1.2 Trial)
// (C) 1998 Ahpah Software Inc
// Please visit our website at http://www.ahpah.com for purchasing information.
//
package com.zsoft.sqlserver;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.Vector;
public final class MyDB {
private static final String DBURL = "jdbc:odbc:db_0";
private static final String DBDRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
private static final String USERNAME = "sa";
private static final String PASSWORD = "password";
// Please visit http://www.sourceagain.com for product information.
public static Connection getConnection()
throws MyException
{
return getConnection( "jdbc:odbc:db_0", "sun.jdbc.odbc.JdbcOdbcDriver", "sa", "password" );
}
// Please visit http://www.sourceagain.com for product information.
public static Connection getConnection(String String1, String String2, String String3, String String4)
throws MyException
{
Object Object7;
Connection Connection8;
try
{
Class.forName( String2 );
}
catch( Exception Exception5 )
{
throw new MyException( "", "u627Eu4E0Du5230u6570u636Eu5E93u7684JDBCu9A71u52A8u7A0Bu5E8F [" + String2 + "]", Exception5 );
}
Object7 = null;
try
{
Connection8 = DriverManager.getConnection( String1, String3, String4 );
Connection8.setAutoCommit( true );
}
catch( Exception Exception6 )
{
Connection8 = null;
throw new MyException( "", "u4E0Du80FDu4EE5u6307u5B9Au7684u7528u6237u540Du548Cu53E3u4EE4u8FDEu4E0Au6570u636Eu5E93", Exception6 );
}
return Connection8;
}
// Please visit http://www.sourceagain.com for product information.
public static String[][] fetchStrData(Connection Connection1, String String2)
throws MyException
{
return fetchStrData( Connection1, String2, 0, 2147418112 );
}
// Please visit http://www.sourceagain.com for product information.
public static String[][] fetchStrData(Connection Connection1, String String2, int int3, int int4)
throws MyException
{
if( Connection1 == null )
throw new MyException( "", "u6570u636Eu5E93u8FDEu63A5u4E3Au7A7A" );
else if( String2 == null )
throw new MyException( "", "SQLu8BEDu53E5u4E3Au7A7A" );
else
{
int int5;
if( int3
// SourceAgain (TM) v1.10 (Core Java 1.2 Trial)
// (C) 1998 Ahpah Software Inc
// Please visit our website at http://www.ahpah.com for purchasing information.
//
package com.zsoft.sqlserver;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.Vector;
public final class MyDB {
private static final String DBURL = "jdbc:odbc:db_0";
private static final String DBDRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
private static final String USERNAME = "sa";
private static final String PASSWORD = "password";
// Please visit http://www.sourceagain.com for product information.
public static Connection getConnection()
throws MyException
{
return getConnection( "jdbc:odbc:db_0", "sun.jdbc.odbc.JdbcOdbcDriver", "sa", "password" );
}
// Please visit http://www.sourceagain.com for product information.
public static Connection getConnection(String String1, String String2, String String3, String String4)
throws MyException
{
Object Object7;
Connection Connection8;
try
{
Class.forName( String2 );
}
catch( Exception Exception5 )
{
throw new MyException( "", "u627Eu4E0Du5230u6570u636Eu5E93u7684JDBCu9A71u52A8u7A0Bu5E8F [" + String2 + "]", Exception5 );
}
Object7 = null;
try
{
Connection8 = DriverManager.getConnection( String1, String3, String4 );
Connection8.setAutoCommit( true );
}
catch( Exception Exception6 )
{
Connection8 = null;
throw new MyException( "", "u4E0Du80FDu4EE5u6307u5B9Au7684u7528u6237u540Du548Cu53E3u4EE4u8FDEu4E0Au6570u636Eu5E93", Exception6 );
}
return Connection8;
}
// Please visit http://www.sourceagain.com for product information.
public static String[][] fetchStrData(Connection Connection1, String String2)
throws MyException
{
return fetchStrData( Connection1, String2, 0, 2147418112 );
}
// Please visit http://www.sourceagain.com for product information.
public static String[][] fetchStrData(Connection Connection1, String String2, int int3, int int4)
throws MyException
{
if( Connection1 == null )
throw new MyException( "", "u6570u636Eu5E93u8FDEu63A5u4E3Au7A7A" );
else if( String2 == null )
throw new MyException( "", "SQLu8BEDu53E5u4E3Au7A7A" );
else
{
int int5;
if( int3