国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
數(shù)據(jù)庫操作類(SQLHelper)
package sqlhelp;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.*;
import java.sql.*;
import javax.servlet.jsp.jstl.sql.Result;
import javax.servlet.jsp.jstl.sql.ResultSupport;

/**
 * 
 * 
@author libiao
 * @date   2008/04/06
 * 功能:
 *         ①:存儲(chǔ)過程有參數(shù)時(shí),Insert/Update処理,返回成功或者失敗的FLG(FLG>0時(shí),表示成功);
 *         ②:存儲(chǔ)過程沒有參數(shù)時(shí),Insert/Update処理,返回成功或者失敗的FLG(FLG>0時(shí),表示成功);
 *         ③:存儲(chǔ)過程有參數(shù)時(shí),Select処理,返回一個(gè)ArrayList;
 *         ④:存儲(chǔ)過程沒有參數(shù)時(shí),Select処理,返回一個(gè)ArrayList;
 *         ⑤:存儲(chǔ)過程有參數(shù)時(shí),Select処理,返回一個(gè)SortedMap[];
 *         ⑥:存儲(chǔ)過程沒有參數(shù)時(shí),Select処理,返回一個(gè)SortedMap[];
 *         ⑦:存儲(chǔ)過程有參數(shù)時(shí),Select処理,返回結(jié)果集中的第一行的name所指定的列的值,當(dāng)結(jié)果集為空時(shí),返回null;
 *         ⑧:存儲(chǔ)過程沒有參數(shù)時(shí),Select処理,返回結(jié)果集中的第一行的name所指定的列的值,當(dāng)結(jié)果集為空時(shí),返回null;
 *         ⑨:存儲(chǔ)過程有參數(shù)時(shí),Select処理,返回結(jié)果集中的第一行的index所指定的列的值,當(dāng)結(jié)果集為空時(shí),返回null;
 *         ⑩:存儲(chǔ)過程沒有參數(shù)時(shí),Select処理,返回結(jié)果集中的第一行的index所指定的列的值,當(dāng)結(jié)果集為空時(shí),返回null;
 * 
 *
 *
 
*/

public class SQLHelper {

    
/**
     * 
@author libiao
     * 
@return Connection
     * 功能:獲得Connection
     
*/

    
private static Connection getConnect() {
        
try {
//            Class.forName("net.sourceforge.jtds.jdbc.Driver");
//            return DriverManager.getConnection("jdbc:jtds:sqlserver://local:1433;DatabaseName=biao;", "sa","");
            return DriverManager.getConnection("proxool.SQL");
        }
 catch (Exception e) {
            System.out.println(
"SQLHepler-getConnect:" + e.getMessage());
            
return null;
        }

    }


    
/**
     * 
     * ①
     * 功能:存儲(chǔ)過程有參數(shù)時(shí),Insert/Update処理,返回成功或者失敗的FLG(FLG>0時(shí),表示成功);
     * 
@author libiao
     * 
@param cmdtext SQL語句/存儲(chǔ)過程名
     * 
@param parms 存儲(chǔ)過程需要的參數(shù)(參數(shù)是以數(shù)組的形式)
     * 
@return 更新成功或者失敗的FLG
     * 
@throws Exception
     * 
     
*/

    
public static int ExecuteNonQuery(String cmdtext, String[] parms) throws Exception {
        PreparedStatement pstmt 
= null;
        Connection conn 
= null;
        
        
try {
            conn 
= getConnect();
            pstmt 
= conn.prepareStatement(cmdtext);
            prepareCommand(pstmt, parms);
            
            
return pstmt.executeUpdate();
            
        }
 catch (Exception e) {
            
throw new Exception("SQLHepler-ExecuteNonQuery-parms:" + e.getMessage());
        }
 finally {
            
try {
                
if (pstmt != null)
                    pstmt.close();
                
if (conn != null)
                    conn.close();
            }
 catch (Exception e) {
                
throw new Exception("SQLHepler-ExecuteNonQuery-parms-close:" + e.getMessage());
            }

        }

    }

    
    
/**
     * 
     * ②
     * 功能:存儲(chǔ)過程沒有參數(shù)時(shí),Insert/Update処理,返回成功或者失敗的FLG(FLG>0時(shí),表示成功);
     * 
@author libiao
     * 
@param cmdtext SQL語句/存儲(chǔ)過程名
     * 
@return 更新成功或者失敗的FLG
     * 
@throws Exception
     * 
     
*/

    
public static int ExecuteNonQuery(String cmdtext) throws Exception {
        PreparedStatement pstmt 
= null;
        Connection conn 
= null;
        
        
try {
            conn 
= getConnect();
            pstmt 
= conn.prepareStatement(cmdtext);
            
            
return pstmt.executeUpdate();
            
        }
 catch (Exception e) {
            
throw new Exception("SQLHepler-ExecuteNonQuery:" + e.getMessage());
        }
 finally {
            
try {
                
if (pstmt != null)
                    pstmt.close();
                
if (conn != null)
                    conn.close();
            }
 catch (Exception e) {
                
throw new Exception("SQLHepler-ExecuteNonQuery-close:" + e.getMessage());
            }

        }

    }

    

    
/**
     * 
     * ③
     * 功能:存儲(chǔ)過程有參數(shù)時(shí),Select処理,返回一個(gè)ArrayList;
     * 
@author libiao
     * 
@param cmdtext SQL語句/存儲(chǔ)過程名
     * 
@param parms 存儲(chǔ)過程需要的參數(shù)(參數(shù)是以數(shù)組的形式)
     * 
@return 結(jié)果集(ArrayList)
     * 
@throws Exception
     
*/

    
public static ArrayList ExecuteReaderList(String cmdtext, String[] parms) throws Exception {
        PreparedStatement pstmt 
= null;
        Connection conn 
= null;
        ResultSet rs 
= null;
        
        
try {
            conn 
= getConnect();            
            pstmt 
= conn.prepareStatement(cmdtext);
            
            prepareCommand(pstmt, parms);
            rs 
= pstmt.executeQuery();
            
            ArrayList
<Object[]> al = new ArrayList<Object[]>();
            ResultSetMetaData rsmd 
= rs.getMetaData();
            
int column = rsmd.getColumnCount();
            
            
while (rs.next()) {
                Object[] ob 
= new Object[column];
                
for (int i = 1; i <= column; i++{
                    ob[i 
- 1= rs.getObject(i);
                }

                al.add(ob);
            }

            
            
return al;
            
        }
 catch (Exception e) {
            
throw new Exception("SQLHepler-ExecuteReaderList-parms:" + e.getMessage());
        }
 finally {
            
try {
                
if (rs != null)
                    rs.close();
                
if (pstmt != null)
                    pstmt.close();
                
if (conn != null)
                    conn.close();
            }
 catch (Exception e) {
                
throw new Exception("SQLHepler-ExecuteReaderList-parms-close:" + e.getMessage());
            }

        }

    }

    
    
    
/**
     * 
     * ④
     * 機(jī)能:存儲(chǔ)過程沒有參數(shù)時(shí),Select処理,返回一個(gè)ArrayList;
     * 
@author libiao
     * 
@param cmdtext SQL語句/存儲(chǔ)過程名
     * 
@return 結(jié)果集(ArrayList)
     * 
@throws Exception
     
*/

    
public static ArrayList ExecuteReaderList(String cmdtext) throws Exception {
        PreparedStatement pstmt 
= null;
        Connection conn 
= null;
        ResultSet rs 
= null;
        
        
try {
            conn 
= getConnect();            
            pstmt 
= conn.prepareStatement(cmdtext);

            rs 
= pstmt.executeQuery();
            
            ArrayList
<Object[]> al = new ArrayList<Object[]>();
            ResultSetMetaData rsmd 
= rs.getMetaData();
            
int column = rsmd.getColumnCount();
            
            
while (rs.next()) {
                Object[] ob 
= new Object[column];
                
for (int i = 1; i <= column; i++{
                    ob[i 
- 1= rs.getObject(i);
                }

                al.add(ob);
            }

            
            
return al;
            
        }
 catch (Exception e) {
            
throw new Exception("SQLHepler-ExecuteReaderList:" + e.getMessage());
        }
 finally {
            
try {
                
if (rs != null)
                    rs.close();
                
if (pstmt != null)
                    pstmt.close();
                
if (conn != null)
                    conn.close();
            }
 catch (Exception e) {
                
throw new Exception("SQLHepler-ExecuteReaderList-close:" + e.getMessage());
            }

        }

    }

    
    
    
/**
     * 
     * ⑤
     * 機(jī)能:存儲(chǔ)過程有參數(shù)時(shí),Select処理,返回一個(gè)SortedMap[];
     * 
@author libiao
     * 
@param cmdtext SQL語句/存儲(chǔ)過程名
     * 
@param parms 存儲(chǔ)過程需要的參數(shù)(參數(shù)是以數(shù)組的形式)
     * 
@return 結(jié)果集(SortedMap[])
     * 
@throws Exception
     
*/

    
public static SortedMap[] ExecuteReaderMap(String cmdtext, String[] parms) throws Exception {
        PreparedStatement pstmt 
= null;
        Connection conn 
= null;
        ResultSet rs 
= null;
        Result result 
= null;
        SortedMap[] sortedMap 
= null;
        
        
try {
            conn 
= getConnect();            
            pstmt 
= conn.prepareStatement(cmdtext);            
            prepareCommand(pstmt, parms);
            rs 
= pstmt.executeQuery();
            
            result 
= ResultSupport.toResult(rs);            
            sortedMap 
= result.getRows();
            
            
return sortedMap;
            
        }
 catch (Exception e) {
            
throw new Exception("SQLHepler-ExecuteReaderMap-parms:" + e.getMessage());
        }
 finally {
            
try {
                
if(rs != null)
                    rs.close();
                
if (pstmt != null)
                    pstmt.close();
                
if (conn != null)
                    conn.close();
            }
 catch (Exception e) {
                
throw new Exception("SQLHepler-ExecuteReaderMap-parms-close:" + e.getMessage());
            }

        }

    }

    

    
/**
     * 
     * ⑥
     * 機(jī)能:存儲(chǔ)過程沒有參數(shù)時(shí),Select処理,返回一個(gè)結(jié)SortedMap[];
     * 
@author libiao
     * 
@param cmdtext SQL語句/存儲(chǔ)過程名
     * 
@return 結(jié)果集(SortedMap[])
     * 
@throws Exception
     
*/

    
public static SortedMap[] ExecuteReaderMap(String cmdtext) throws Exception {
        PreparedStatement pstmt 
= null;
        Connection conn 
= null;
        ResultSet rs 
= null;
        Result result 
= null;
        SortedMap[] sortedMap 
= null;
        
        
try {
            conn 
= getConnect();            
            pstmt 
= conn.prepareStatement(cmdtext);
            rs 
= pstmt.executeQuery();
            
            result 
= ResultSupport.toResult(rs);            
            sortedMap 
= result.getRows();
            
            
return sortedMap;
            
        }
 catch (Exception e) {
            
throw new Exception("SQLHepler-ExecuteReaderMap:" + e.getMessage());
        }
 finally {
            
try {
                
if(rs != null)
                    rs.close();
                
if (pstmt != null)
                    pstmt.close();
                
if (conn != null)
                    conn.close();
            }
 catch (Exception e) {
                
throw new Exception("SQLHepler-ExecuteReaderMap-close:" + e.getMessage());
            }

        }

    }

    

    
/**
     * 
     * ⑦
     * 機(jī)能:存儲(chǔ)過程有參數(shù)時(shí),Select処理,返回結(jié)果集中的第一行的name所指定的列的值,當(dāng)結(jié)果集為空時(shí),返回null
     * 
@author libiao
     * 
@param cmdtext SQL語句/存儲(chǔ)過程名
     * 
@param name 需要取る列名
     * 
@param parms 存儲(chǔ)過程需要的參數(shù)(參數(shù)是以數(shù)組的形式)
     * 
@return 結(jié)果集中的第一行的name所指定的列的值,當(dāng)結(jié)果集為空時(shí),返回null
     * 
@throws Exception
     
*/

    
public static Object ExecuteScalar(String cmdtext, String name,String[] parms) throws Exception {
        PreparedStatement pstmt 
= null;
        Connection conn 
= null;
        ResultSet rs 
= null;
        
        
try {
            conn 
= getConnect();
            
            pstmt 
= conn.prepareStatement(cmdtext);
            prepareCommand(pstmt, parms);
            
            rs 
= pstmt.executeQuery();
            
if (rs.next()) {
                
return rs.getObject(name);
            }
 else {
                
return null;
            }

        }
 catch (Exception e) {
            
throw new Exception("SQLHepler-ExecuteScalar-name-parms:" + e.getMessage());
        }
 finally {
            
try {
                
if (rs != null)
                    rs.close();
                
if (pstmt != null)
                    pstmt.close();
                
if (conn != null)
                    conn.close();
            }
 catch (Exception e) {
                
throw new Exception("SQLHepler-ExecuteScalar-name-parms-close:" + e.getMessage());
            }

        }

    }

    
    
    
/**
     * 
     * ⑧
     * 機(jī)能:存儲(chǔ)過程沒有參數(shù)時(shí),Select処理,返回結(jié)果集中的第一行的name所指定的列的值,當(dāng)結(jié)果集為空時(shí),返回null
     * 
@author libiao
     * 
@param cmdtext SQL語句/存儲(chǔ)過程名
     * 
@param name 需要取る列名
     * 
@return 結(jié)果集中的第一行的name所指定的列的值,當(dāng)結(jié)果集為空時(shí),返回null
     * 
@throws Exception
     
*/

    
public static Object ExecuteScalar(String cmdtext, String name) throws Exception {
        PreparedStatement pstmt 
= null;
        Connection conn 
= null;
        ResultSet rs 
= null;
        
        
try {
            conn 
= getConnect();
            
            pstmt 
= conn.prepareStatement(cmdtext);
            
            rs 
= pstmt.executeQuery();
            
if (rs.next()) {
                
return rs.getObject(name);
            }
 else {
360docimg_502_                
return null;
360docimg_503_            }

360docimg_504_360docimg_505_        }
 catch (Exception e) {
360docimg_507_            
throw new Exception("SQLHepler-ExecuteScalar-name:" + e.getMessage());
360docimg_508_360docimg_509_        }
 finally {
360docimg_511_360docimg_512_            
try {
360docimg_514_                
if (rs != null)
360docimg_515_                    rs.close();
360docimg_516_                
if (pstmt != null)
360docimg_517_                    pstmt.close();
360docimg_518_                
if (conn != null)
360docimg_519_                    conn.close();
360docimg_520_360docimg_521_            }
 catch (Exception e) {
360docimg_523_                
throw new Exception("SQLHepler-ExecuteScalar-name-close:" + e.getMessage());
360docimg_524_            }

360docimg_525_        }

360docimg_526_    }

360docimg_527_    
360docimg_528_    
360docimg_529_360docimg_530_    
/**
360docimg_531_     * 
360docimg_532_     * ⑨
360docimg_533_     * 機(jī)能:存儲(chǔ)過程有參數(shù)時(shí),Select処理,返回結(jié)果集中的第一行的index所指定的列的值,當(dāng)結(jié)果集為空時(shí),返回null
360docimg_534_     * 
@author libiao
360docimg_535_     * 
@param cmdtext SQL語句/存儲(chǔ)過程名
360docimg_536_     * 
@param index 需要取る列番號(hào)
360docimg_537_     * 
@param parms 存儲(chǔ)過程需要的參數(shù)(參數(shù)是以數(shù)組的形式)
360docimg_538_     * 
@return 結(jié)果集中的第一行的index所指定的列的值,當(dāng)結(jié)果集為空時(shí),返回null
360docimg_539_     * 
@throws Exception
360docimg_540_     
*/

360docimg_541_360docimg_542_    
public static Object ExecuteScalar(String cmdtext, int index, String[] parms) throws Exception {
360docimg_544_        PreparedStatement pstmt 
= null;
360docimg_545_        Connection conn 
= null;
360docimg_546_        ResultSet rs 
= null;
360docimg_547_        
360docimg_548_360docimg_549_        
try {
360docimg_551_            conn 
= getConnect();            
360docimg_552_            pstmt 
= conn.prepareStatement(cmdtext);
360docimg_553_            prepareCommand(pstmt, parms);
360docimg_554_            
360docimg_555_            rs 
= pstmt.executeQuery();
360docimg_556_360docimg_557_            
if (rs.next()) {
360docimg_559_                
return rs.getObject(index);
360docimg_560_360docimg_561_            }
 else {
360docimg_563_                
return null;
360docimg_564_            }

360docimg_565_360docimg_566_        }
 catch (Exception e) {
360docimg_568_            
throw new Exception("SQLHepler-ExecuteScalar-index-parms:" + e.getMessage());
360docimg_569_360docimg_570_        }
 finally {
360docimg_572_360docimg_573_            
try {
360docimg_575_                
if (rs != null)
360docimg_576_                    rs.close();
360docimg_577_                
if (pstmt != null)
360docimg_578_                    pstmt.close();
360docimg_579_                
if (conn != null)
360docimg_580_                    conn.close();
360docimg_581_360docimg_582_            }
 catch (Exception e) {
360docimg_584_                
throw new Exception("SQLHepler-ExecuteScalar-index-parms-close:" + e.getMessage());
360docimg_585_            }

360docimg_586_        }

360docimg_587_    }

360docimg_588_    
360docimg_589_    
360docimg_590_360docimg_591_    
/**
360docimg_592_     * 
360docimg_593_     * ⑩
360docimg_594_     * 機(jī)能:存儲(chǔ)過程沒有參數(shù)時(shí),Select処理,返回結(jié)果集中的第一行的index所指定的列的值,當(dāng)結(jié)果集為空時(shí),返回null
360docimg_595_     * 
@author libiao
360docimg_596_     * 
@param cmdtext SQL語句/存儲(chǔ)過程名
360docimg_597_     * 
@param index 需要取る列番號(hào)
360docimg_598_     * 
@return 結(jié)果集中的第一行的index所指定的列的值,當(dāng)結(jié)果集為空時(shí),返回null
360docimg_599_     * 
@throws Exception
360docimg_600_     
*/

360docimg_601_360docimg_602_    
public static Object ExecuteScalar(String cmdtext, int index) throws Exception {
360docimg_604_        PreparedStatement pstmt 
= null;
360docimg_605_        Connection conn 
= null;
360docimg_606_        ResultSet rs 
= null;
360docimg_607_        
360docimg_608_360docimg_609_        
try {
360docimg_611_            conn 
= getConnect();            
360docimg_612_            pstmt 
= conn.prepareStatement(cmdtext);
360docimg_613_            
360docimg_614_            rs 
= pstmt.executeQuery();
360docimg_615_360docimg_616_            
if (rs.next()) {
360docimg_618_                
return rs.getObject(index);
360docimg_619_360docimg_620_            }
 else {
360docimg_622_                
return null;
360docimg_623_            }

360docimg_624_360docimg_625_        }
 catch (Exception e) {
360docimg_627_            
throw new Exception("SQLHepler-ExecuteScalar-index:" + e.getMessage());
360docimg_628_360docimg_629_        }
 finally {
360docimg_631_360docimg_632_            
try {
360docimg_634_                
if (rs != null)
360docimg_635_                    rs.close();
360docimg_636_                
if (pstmt != null)
360docimg_637_                    pstmt.close();
360docimg_638_                
if (conn != null)
360docimg_639_                    conn.close();
360docimg_640_360docimg_641_            }
 catch (Exception e) {
360docimg_643_                
throw new Exception("SQLHepler-ExecuteScalar-index-close:" + e.getMessage());
360docimg_644_            }

360docimg_645_        }

360docimg_646_    }

360docimg_647_
360docimg_648_
360docimg_649_360docimg_650_    
/**
360docimg_651_     * 
360docimg_652_     * 機(jī)能:分割參數(shù)數(shù)組,并且插入到PreparedStatement對(duì)象中
360docimg_653_     * 
@author libiao
360docimg_654_     * 
@param pstmt PreparedStatement対象
360docimg_655_     * 
@param parms 存儲(chǔ)過程需要的參數(shù)(參數(shù)是以數(shù)組的形式)
360docimg_656_     * 
@return 
360docimg_657_     * 
@throws Exception
360docimg_658_     
*/

360docimg_659_360docimg_660_    
private static void prepareCommand(PreparedStatement pstmt, String[] parms) throws Exception {
360docimg_662_360docimg_663_        
try {
360docimg_665_360docimg_666_            
if (parms != null{
360docimg_668_360docimg_669_                
for (int i = 0; i < parms.length; i++{
360docimg_671_360docimg_672_                    
/*
360docimg_673_                    try {
360docimg_674_                        pstmt.setString(i + 1, parms[i]);
360docimg_675_                    } catch (Exception errs) {
360docimg_676_                        System.out.print("SQLHelper-PrepareCommand ErrString:"+ errs);
360docimg_677_                    }
*/

360docimg_678_                    
360docimg_679_360docimg_680_                    
try {
360docimg_682_                        pstmt.setDate(i 
+ 1, java.sql.Date.valueOf(parms[i]));
360docimg_683_360docimg_684_                    }
 catch (Exception e) {
360docimg_686_360docimg_687_                        
try {
360docimg_689_                            pstmt.setDouble(i 
+ 1, Double.parseDouble(parms[i]));
360docimg_690_360docimg_691_                        }
 catch (Exception e1) {
360docimg_693_360docimg_694_                            
try {
360docimg_696_                                pstmt.setInt(i 
+ 1, Integer.parseInt(parms[i]));
360docimg_697_360docimg_698_                            }
 catch (Exception e2) {
360docimg_700_360docimg_701_                                
try {
360docimg_703_                                    pstmt.setString(i 
+ 1, parms[i]);
360docimg_704_360docimg_705_                                }
 catch (Exception errs) {
360docimg_707_                                    System.out.print(
"SQLHelper-PrepareCommand ErrString:"+ errs);
360docimg_708_                                }

360docimg_709_                            }

360docimg_710_                        }

360docimg_711_                    }

360docimg_712_                }

360docimg_713_            }

360docimg_714_360docimg_715_        }
 catch (Exception e) {
360docimg_717_            System.out.print(
"SQLHelper-PrepareCommand Error:" + e);
360docimg_718_        }

360docimg_719_    }

360docimg_720_}

360docimg_721_
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
什么是同構(gòu)與異構(gòu)?及在不同背景下的理解
JDBC
用java調(diào)用oracle存儲(chǔ)過程總結(jié) 3 - 返回列表-偶愛老婆-搜狐博客
JDBC執(zhí)行存儲(chǔ)過程的四種情況
Java的JDBC操作
struct加Ajax (5)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服