第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

為什么驅(qū)動(dòng)老是加載失敗 conn 為null , Class.forName(driverClassName) 這種方式加載有問(wèn)題?

為什么驅(qū)動(dòng)老是加載失敗 conn 為null , Class.forName(driverClassName) 這種方式加載有問(wèn)題?

慕粉3430898 2017-12-29 14:37:16
為什么老提示? 類加載驅(qū)動(dòng)失敗呢?package com.iok.jee.dbc;import com.mysql.jdbc.*;import java.sql.*;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.Statement;import java.util.Properties;import ?java.sql.DriverManager;/** * Created by Administrator on 2018/1/20 0020. */public class Dbutils { ? ?private static Properties ? properties; ? ?private static String ?driverClassName; ? ?private static String url; ? ?private static String userName; ? ?private static String password; ? ?static { ? ? ? ?try { ? ? ? ? ? ?properties = new Properties(); ? ? ? ? ? ?properties.load(Dbutils.class.getClassLoader().getResourceAsStream("jdbc.properties")); ? ? ? ? ? ?driverClassName = properties.getProperty("driverClassName"); ? ? ? ? ? ?url = properties.getProperty("url"); ? ? ? ? ? ?userName = properties.getProperty("userName"); ? ? ? ? ? ?password = properties.getProperty("password"); ? ? ? ? ? ?Class.forName(driverClassName);/*加載驅(qū)動(dòng)*/ ? ? ? ? /* ? DriverManager.registerDriver(new com.mysql.jdbc.Driver());*/ ? ? ? ?}catch (Exception e){ ? ? ? ? ? ?throw ?new ExceptionInInitializerError("類加載驅(qū)動(dòng)失?。?); ? ? ? ?} ? ?} ? ?/*連接驅(qū)動(dòng)*/ ? ?public ?static Connection getConnection(){ ? ? ? ? ?Connection conn=null; ? ? ? ?try{ ? ? ? ? conn = ? DriverManager.getConnection(url,userName,password); ? ? ? ?}catch (SQLException e){ ? ? ? ? ? ?e.printStackTrace();; ? ? ? ?} ? ? ? ?return ?conn; ? ?} ? ?/*獲取語(yǔ)句對(duì)象*/ ? ?public ?static java.sql.Statement getStatment(java.sql.Connection ?conn){ ? ? ? ?java.sql.Statement stat=null; ? ? ? ?if(conn==null){ ? ? ? ? ? ?throw ?new IllegalArgumentException("連接對(duì)象為空無(wú)法獲取語(yǔ)句對(duì)象"); ? ? ? ?} ? ? ? ?try{ ? ? ? ? ? ?stat= conn.createStatement(); ? ? ? ?}catch (SQLException e){ ? ? ? ? ? ? ?e.printStackTrace();; ? ? ? ?} ? ? ? ? ? ? return ?stat; ? ? }/*獲取預(yù)編譯語(yǔ)句對(duì)象*/ ? ?public ?static java.sql.PreparedStatement getPreparedStatement(java.sql.Connection ?conn,String sql){ ? ? ? ? PreparedStatement ?preparedStat=null; ? ? ? ?if(conn==null){ ? ? ? ? ? ?throw ?new IllegalArgumentException("連接對(duì)象為空無(wú)法獲取預(yù)編譯語(yǔ)句對(duì)象"); ? ? ? ?} ? ? ? ?if(sql==null||"".equals(sql)){ ? ? ? ? ? ?throw ?new IllegalArgumentException("sql語(yǔ)句為空無(wú)法獲取預(yù)編譯語(yǔ)句對(duì)象"); ? ? ? ?} ? ? ? ?try{ ? ? ? ? ? ?preparedStat= conn.prepareStatement(sql); ? ? ? ?}catch (SQLException e){ ? ? ? ? ? ?e.printStackTrace();; ? ? ? ?} ? ? ? ?return ?preparedStat; ? ?} ? ?public ?static ?void ?closeConnection ?(java.sql.Connection conn){ ? ? ? ? ? try{ ? ? ? ? ? ? ? if(conn!=null){/*如果連接不為空*/ ? ? ? ? ? ? ? ? ? if(!conn.isClosed()){/*如果連接未關(guān)閉*/ ? ? ? ? ? ? ? ? ? ? ? conn.close();/*關(guān)閉連接*/ ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? } ? ? ? ? ? }catch (SQLException e){ ? ? ? ? ? ? ? e.printStackTrace(); ? ? ? ? ? } ? ? ? ? ? } ? ?/*關(guān)閉語(yǔ)句對(duì)象*/ ? ?public ?static ?void ?closeStatement (java.sql.Statement stat){ ? ? ? ?try{ ? ? ? ? ? ?if(stat!=null){/*如果連接不為空*/ ? ? ? ? ? ? ? ?if(!stat.isClosed()){/*如果連接未關(guān)閉*/ ? ? ? ? ? ? ? ? ? ?stat.close();/*關(guān)閉連接*/ ? ? ? ? ? ? ? ?} ? ? ? ? ? ?} ? ? ? ?}catch (SQLException e){ ? ? ? ? ? ?e.printStackTrace(); ? ? ? ?} ? ?} ? ?/*關(guān)閉結(jié)果集*/ ? ?public ?static ?void ?closeResult (ResultSet rs){ ? ? ? ?try{ ? ? ? ? ? ?if(rs!=null){/*如果連接不為空*/ ? ? ? ? ? ? ? ?if(!rs.isClosed()){/*如果連接未關(guān)閉*/ ? ? ? ? ? ? ? ? ? ?rs.close();/*關(guān)閉連接*/ ? ? ? ? ? ? ? ?} ? ? ? ? ? ?} ? ? ? ?}catch (SQLException e){ ? ? ? ? ? ?e.printStackTrace(); ? ? ? ?} ? ?}}
查看完整描述

2 回答

  • 2 回答
  • 0 關(guān)注
  • 1621 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)