亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

DBHelper我是copy上一個jsp項目的代碼,但就是要報異常這個怎么解決?

package util;


import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;


public class DBHelper {

//數據庫驅動

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

? ?//鏈接數據庫的URL地址

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

? ?//數據庫的用戶名

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

? ?//數據庫的密碼

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


? ?private static Connection conn = null;


? ?//靜態代碼塊負責加載驅動

? ? static

? ? {

? ? try

? ? {

? ? Class.forName(driver);

? ? }

? ? catch(Exception ex)

? ? {

? ? ex.getStackTrace();

? ? }

? ? }


? ? //單例模式返回數據庫連接對象

? ? 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("數據庫連接正常!");

? ? }

? ? else

? ? {

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

? ? }

? ? }

? ? catch(Exception ex)

? ? {?

? ? ?ex.getStackTrace();

? ? }

? ?

}


}


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


正在回答

2 回答

你看看你的數據庫中有沒有shopping這個數據庫

0 回復 有任何疑惑可以回復我~

JdbcUrl還可以這么寫的嗎?

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

DBHelper我是copy上一個jsp項目的代碼,但就是要報異常這個怎么解決?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號