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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么類加載驅(qū)動失敗 conn為null , Class.forName(driverClassName);加載方式是否有問題?

為什么類加載驅(qū)動失敗 conn為null , Class.forName(driverClassName);加載方式是否有問題?

慕粉3430898 2018-01-21 17:22:50
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ū)動*/? ? ? ? /* ? DriverManager.registerDriver(new com.mysql.jdbc.Driver());*/? ? ? ?}catch (Exception e){? ? ? ? ? ?throw ?new ExceptionInInitializerError("類加載驅(qū)動失敗!");? ? ? ?}? ?}? ?/*連接驅(qū)動*/? ?public ?static Connection getConnection(){? ? ? ? ?Connection conn=null;? ? ? ?try{? ? ? ? conn = ? DriverManager.getConnection(url,userName,password);? ? ? ?}catch (SQLException e){? ? ? ? ? ?e.printStackTrace();;? ? ? ?}? ? ? ?return ?conn;? ?}? ?/*獲取語句對象*/? ?public ?static java.sql.Statement getStatment(java.sql.Connection ?conn){? ? ? ?java.sql.Statement stat=null;? ? ? ?if(conn==null){? ? ? ? ? ?throw ?new IllegalArgumentException("連接對象為空無法獲取語句對象");? ? ? ?}? ? ? ?try{? ? ? ? ? ?stat= conn.createStatement();? ? ? ?}catch (SQLException e){? ? ? ? ? ? ?e.printStackTrace();;? ? ? ?}? ? ? ? ? ? return ?stat;? ? }/*獲取預(yù)編譯語句對象*/? ?public ?static java.sql.PreparedStatement getPreparedStatement(java.sql.Connection ?conn,String sql){? ? ? ? PreparedStatement ?preparedStat=null;? ? ? ?if(conn==null){? ? ? ? ? ?throw ?new IllegalArgumentException("連接對象為空無法獲取預(yù)編譯語句對象");? ? ? ?}? ? ? ?if(sql==null||"".equals(sql)){? ? ? ? ? ?throw ?new IllegalArgumentException("sql語句為空無法獲取預(yù)編譯語句對象");? ? ? ?}? ? ? ?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)閉語句對象*/? ?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回答
查看完整描述

目前暫無任何回答

  • 0 回答
  • 0 關(guān)注
  • 1420 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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