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

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

數(shù)據(jù)庫鏈接異常怎么處理啊,shopping已在navicat創(chuàng)建

package util;


import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;


public class DBHelper {

//數(shù)據(jù)庫驅(qū)動(dòng)

? ?private static final String driver = "com.mysql.jdbc.Driver";

? ?//鏈接數(shù)據(jù)庫的URL地址

? ?private static final String url="jdbc:mysql://localhost:3306/shopping?useUnicode=true&characterEncoding=UTF";

? ?//數(shù)據(jù)庫的用戶名

? ?private static final String username = "root";

? ?//數(shù)據(jù)庫的密碼

? ?private static final String password = "";//


? ?private static Connection conn=null;


? ?//靜態(tài)代碼塊負(fù)責(zé)加載驅(qū)動(dòng)

? ? static

? ? {

? ? try

? ? {

? ? Class.forName(driver);

? ? }

? ? catch(Exception ex)

? ? {

? ? ex.getStackTrace();

? ? }

? ? }


? ? //單例模式返回?cái)?shù)據(jù)庫連接對象

? ? public static Connection getConnection() throws Exception

? ? {

? ? if(conn!=null)

? ? {

? ? conn = DriverManager.getConnection(url, username, password);

? ? ? ?return conn;

? ? }

? ? return conn;

? ? }

? ??

? ? public static void main(String[] args) {

? ? try

? ? {

? ? Connection conn = DBHelper.getConnection();

? ? if(conn!=null)

? ? {

? ? System.out.println("數(shù)據(jù)庫連接正常!");

? ? }

? ? else

? ? {

? ? System.out.println("數(shù)據(jù)庫連接異常!");

? ? }

? ? }

? ? catch(Exception ex)

? ? {

? ? ?ex.getStackTrace();

? ? }

? ?

}


}


正在回答

1 回答

characterEncoding=UTF?? 寫錯(cuò)了吧? charactorencoding=UTF

1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

690017359 提問者

非常感謝!
2017-09-24 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
JAVA遇見HTML——JSP篇
  • 參與學(xué)習(xí)       248277    人
  • 解答問題       3198    個(gè)

Java Web入門級教程JSP,帶你輕松的學(xué)習(xí)JSP基礎(chǔ)知識

進(jìn)入課程

數(shù)據(jù)庫鏈接異常怎么處理啊,shopping已在navicat創(chuàng)建

我要回答 關(guān)注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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