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

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

DBHelper我是copy上一個(gè)jsp項(xiàng)目的代碼,但就是要報(bào)異常這個(gè)怎么解決?

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-8";

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

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

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

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


? ?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ù)庫連接對(duì)象

? ? 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();

? ? }

? ?

}


}


這個(gè)是報(bào)的異常:java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/shopping?useUnicode=true&characterEncoding=UTF-8


正在回答

2 回答

你看看你的數(shù)據(jù)庫中有沒有shopping這個(gè)數(shù)據(jù)庫

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

JdbcUrl還可以這么寫的嗎?

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

舉報(bào)

0/150
提交
取消

DBHelper我是copy上一個(gè)jsp項(xiàng)目的代碼,但就是要報(bào)異常這個(gè)怎么解決?

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

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

幫助反饋 APP下載

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

公眾號(hào)

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