jdbc
package dbsql;
import java.sql.*;
import javax.naming.*;
import java.sql.*;
import javax.sql.*;
import java.math.BigDecimal;
import java.util.*;
import java.text.*;
public class dbsql
{
InitialContext ic =null;
DataSource ds =null;
Connection conn = null;
public boolean con() throws SQLException
{
try{
ic = new InitialContext();
ds = (DataSource) ic.lookup("java:/OracleDS");
conn = ds.getConnection();
}
catch (Exception sqle)
{
sqle.printStackTrace();
return false;
}
return true;
}
public ResultSet createExcuteQuery(String sql) throws SQLException {
try{
Statement pstmt = conn.createStatement();
ResultSet rs = pstmt.executeQuery(sql);
}
catch( Exception sqle ) {
sqle.printStackTrace();
return null;
}
finally
{
return rs;
rs.close();
pstmt.close();
}
} //end of PrepareExcuteQuery
}
public ResultSet PrepareExcuteQuery(String sql) throws SQLException
{ try{
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
}
catch( Exception sqle ) {
sqle.printStackTrace();
return null;
}
finally
{
return rs;
rs.close();
pstmt.close();
}
} //end of PrepareExcuteQuery
public int createExecuteUpdate (String sql)throws SQLException
{
try{
Statement pstmt = conn.createStatement();
int sum= pstmt.executeUpdate( sql);
}
catch( Exception sqle ) {
sqle.printStackTrace();
return 0;
}
finally
{
return sum;
pstmt.close();
}
}
public int PrepareExcuteUpdate(String sql)throws SQLException
{
try {
PreparedStatement pstmt = conn.prepareStatement(sql);
int sum= pstmt.executeUpdate();
}
catch( Exception sqle ) {
sqle.printStackTrace();
return 0;
}
finally
{
return sum;
pstmt.close();
}
}
public boolean createExecute(String sql)throws SQLException
{
try {
Statement pstmt = conn.createStatement();
pstmt.execute(sql);
}
catch( Exception sqle ) {
sqle.printStackTrace();
return false;
}
finally
{
return true;
pstmt.close();
}
}
public boolean PrepareExecute(String sql) throws SQLException
{
try
{
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.execute();
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
return false;
}
finally
{
return true;
pstmt.close();
}
}
public void connclose()
{
try { conn.close(); }
catch (Exception e) { e.printStackTrace(); }
}
}
import java.sql.*;
import javax.naming.*;
import java.sql.*;
import javax.sql.*;
import java.math.BigDecimal;
import java.util.*;
import java.text.*;
public class dbsql
{
InitialContext ic =null;
DataSource ds =null;
Connection conn = null;
public boolean con() throws SQLException
{
try{
ic = new InitialContext();
ds = (DataSource) ic.lookup("java:/OracleDS");
conn = ds.getConnection();
}
catch (Exception sqle)
{
sqle.printStackTrace();
return false;
}
return true;
}
public ResultSet createExcuteQuery(String sql) throws SQLException {
try{
Statement pstmt = conn.createStatement();
ResultSet rs = pstmt.executeQuery(sql);
}
catch( Exception sqle ) {
sqle.printStackTrace();
return null;
}
finally
{
return rs;
rs.close();
pstmt.close();
}
} //end of PrepareExcuteQuery
}
public ResultSet PrepareExcuteQuery(String sql) throws SQLException
{ try{
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
}
catch( Exception sqle ) {
sqle.printStackTrace();
return null;
}
finally
{
return rs;
rs.close();
pstmt.close();
}
} //end of PrepareExcuteQuery
public int createExecuteUpdate (String sql)throws SQLException
{
try{
Statement pstmt = conn.createStatement();
int sum= pstmt.executeUpdate( sql);
}
catch( Exception sqle ) {
sqle.printStackTrace();
return 0;
}
finally
{
return sum;
pstmt.close();
}
}
public int PrepareExcuteUpdate(String sql)throws SQLException
{
try {
PreparedStatement pstmt = conn.prepareStatement(sql);
int sum= pstmt.executeUpdate();
}
catch( Exception sqle ) {
sqle.printStackTrace();
return 0;
}
finally
{
return sum;
pstmt.close();
}
}
public boolean createExecute(String sql)throws SQLException
{
try {
Statement pstmt = conn.createStatement();
pstmt.execute(sql);
}
catch( Exception sqle ) {
sqle.printStackTrace();
return false;
}
finally
{
return true;
pstmt.close();
}
}
public boolean PrepareExecute(String sql) throws SQLException
{
try
{
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.execute();
}
catch(SQLException ex)
{
System.err.println(ex.getMessage());
return false;
}
finally
{
return true;
pstmt.close();
}
}
public void connclose()
{
try { conn.close(); }
catch (Exception e) { e.printStackTrace(); }
}
}
haohao
2004-07-30 14:01:53
评论:0
阅读:836
引用:0
关于这
@2004-07-30 14:03:15 haohao
这个dbsql
还特别幼稚的.
不过包含挺全的.
还特别幼稚的.
不过包含挺全的.
