• 
    

      <address id="upfr9"><pre id="upfr9"><strike id="upfr9"></strike></pre></address>
      1. <address id="upfr9"><tr id="upfr9"></tr></address><dl id="upfr9"></dl>

        新浪云web項(xiàng)目數(shù)據(jù)庫(kù)連接及封裝

        【重點(diǎn)】Class.forName("com.MySQL.jdbc.Driver");//數(shù)據(jù)庫(kù)連接語(yǔ)句聲明

        創(chuàng)新互聯(lián)致力于成都網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè),成都網(wǎng)站設(shè)計(jì),集團(tuán)網(wǎng)站建設(shè)等服務(wù)標(biāo)準(zhǔn)化,推過(guò)標(biāo)準(zhǔn)化降低中小企業(yè)的建站的成本,并持續(xù)提升建站的定制化服務(wù)水平進(jìn)行質(zhì)量交付,讓企業(yè)網(wǎng)站從市場(chǎng)競(jìng)爭(zhēng)中脫穎而出。 選擇創(chuàng)新互聯(lián),就選擇了安全、穩(wěn)定、美觀的網(wǎng)站建設(shè)服務(wù)!

        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bbs","root","root"); //本地mysql數(shù)據(jù)庫(kù)JDBC連接語(yǔ)句(項(xiàng)目名bbs登錄名root密碼root)

        conn = DriverManager.getConnection("jdbc:mysql://w.rdc.sae.sina.com.cn:3307/app_xiaoweibbs","0ww4ox1l0n","4ik4i5jkwwmxij0lyjl3hmlx3kkyyi1ii10iih33");

        //新浪云mysql數(shù)據(jù)庫(kù)JDBC連接語(yǔ)句(云數(shù)據(jù)庫(kù)地址和端口固定“w.rdc.sae.sina.com.cn:3307”web應(yīng)用名稱前面要加上app_ 然后找到web應(yīng)用設(shè)置類似0ww4ox1l0n的數(shù)據(jù)庫(kù)登錄名和類似4ik4i5jkwwmxij0lyjl3hmlx3kkyyi1ii10iih33這樣的數(shù)據(jù)庫(kù)登錄密碼)

        【一】下面是我自己的bbs數(shù)據(jù)庫(kù)的封裝代碼:

        package com.bjsxt.bbs;  //包名要記得改掉

        import com.mysql.jdbc.Statement;

        import java.sql.*;

        public class DB {

            public static Connection getConn(){

            Connection conn = null;

        try {

        Class.forName("com.mysql.jdbc.Driver");

        //conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bbs","root","root");

        conn = DriverManager.getConnection("jdbc:mysql://w.rdc.sae.sina.com.cn:3307/app_xiaoweibbs","0ww4ox1l0n","4ik4i5jkwwmxij0lyjl3hmlx3kkyyi1ii10iih33");

        } catch (ClassNotFoundException e) {

        e.printStackTrace();

        }catch (SQLException e) {

        e.printStackTrace();

        e.printStackTrace();

        }

            return conn;

           

            }

            

            public static Statement createStmt(Connection conn){

            Statement stmt = null;

            try {

                    stmt = (Statement) conn.createStatement();

            } catch (SQLException e){

            e.printStackTrace();

            }

            return stmt;

            }

            

            public static ResultSet ExceruQuery(Statement stmt,String sql){

            ResultSet rs = null;

                     try {

        rs = stmt.executeQuery(sql);

        } catch (SQLException e) {

        e.printStackTrace();

        }

            return rs;

            }

            

            public static int executeUpdate(Connection conn,String sql){

            int ret = 0;

            Statement stmt = null;

            try{

            stmt = (Statement) conn.createStatement();

            ret = stmt.executeUpdate(sql);

            }catch(SQLException e){

            e.printStackTrace();

            } finally {

            close(stmt);

            }

            return ret;

            }

            public static void close(Connection conn){

            if(conn != null){

            try {

        conn.close();

        } catch (SQLException e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

        }

            }

            conn = null;

            }

            public static void close(Statement stmt){

            if(stmt != null){

            try {

        stmt.close();

        } catch (SQLException e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

        }

            }

            stmt = null;

            }

            public static void close(ResultSet rs){

            if(rs != null){

            try {

        rs.close();

        } catch (SQLException e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

        }

            }

            rs = null;

            }

         

            public static PreparedStatement PreparedStmt(Connection conn,String sql){

            PreparedStatement pstmt =null;

            try {

        pstmt = conn.prepareStatement(sql);

        } catch (SQLException e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

        }

            return pstmt;

            }

            public static PreparedStatement PreparedStmt(Connection conn,String sql,int autoGeneratedKeys){

            PreparedStatement pstmt =null;

            try {

        pstmt = conn.prepareStatement(sql,autoGeneratedKeys);

        } catch (SQLException e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

        }

            return pstmt;

            }

            public static void close(PreparedStatement pstmt){

            if(pstmt != null){

            try {

        pstmt.close();

        } catch (SQLException e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

        }

            }

            pstmt = null;

            }

        }

        文章題目:新浪云web項(xiàng)目數(shù)據(jù)庫(kù)連接及封裝
        分享網(wǎng)址:http://www.jbt999.com/article8/jeidip.html

        成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站建設(shè)、App設(shè)計(jì)標(biāo)簽優(yōu)化、Google網(wǎng)站制作

        廣告

        聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

        商城網(wǎng)站建設(shè)

      2. 
        

          <address id="upfr9"><pre id="upfr9"><strike id="upfr9"></strike></pre></address>
          1. <address id="upfr9"><tr id="upfr9"></tr></address><dl id="upfr9"></dl>
            特黄AAAAAAAAA级毛片厂 | 欧美三级片在线 | 久久夜色精品国产免费观看 | 第一狼人综合网 | 男人天堂最新地址 | 国产吧在线观看 | 高清无码影音 | 五月婷婷精品 | 国产婷婷婷婷 | 国产婷婷久久 |