本文目錄一覽:
- 1、java連接mysql錯誤
- 2、java 連接資料庫mysql 的錯誤
- 3、java 連接mysql資料庫產生了錯誤
- 4、JAVA連接mysql資料庫報錯,坐等高手指點
- 5、java連接MySQL資料庫報錯java.lang.ClassNotFoundException
- 6、java連接mysql資料庫報錯
java連接mysql錯誤
import java.sql.*;
public class Jdbc {
public static void main(String args[]) {
try {
Class.forName(“com.mysql.cj.jdbc.Driver”); //載入MYSQL JDBC驅動程序
System.out.println(“Success loading Mysql Driver!”);
}
catch (Exception e) {
System.out.print(“Error loading Mysql Driver!”);
e.printStackTrace();
}
try {
Connection connect = DriverManager.getConnection(
“jdbc:mysql://localhost:3306/shop?serverTimezone=UTC”,”root”,”1437790929″);//java這個空填寫的是你自己設的密碼
System.out.println(“Success connect Mysql!”);
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery(“select * from user”);
//user 為你表的名稱,可以在MySQL命令行用show tables;顯示
while (rs.next()) {
System.out.println(rs.getString(“name”));
}
}
catch (Exception e) {
System.out.print(“get data error!”);
e.printStackTrace();
}
}
}
java 連接資料庫mysql 的錯誤
對應你資料庫的jdbc的jar包只有一個,你把這三個都從工程里刪除,然後在網上找一個對應你資料庫的jdbc的jar包(不同資料庫對應不同的jar包),添加進去就可以了,你添加三個是有問題的,肯定會發生衝突
java 連接mysql資料庫產生了錯誤
1,百度搜索你的mysql版本是不是和連接驅動一致。
2,錯誤顯示,你的連接驅動沒找到,看看你導入到項目沒有。
JAVA連接mysql資料庫報錯,坐等高手指點
package tju.calendar.dbc;
import java.sql.Connection;
import java.sql.DriverManager;
public class DatabaseConnection {
private static final String DBDRIVER=”com.mysql.jdbc.Driver”;
private static final String DBURL=”jdbc:mysql://localhost:3306/–“;
private static final String DBUSER=”–“;
private static final String DBPASSWARD=”—“;
private Connection conn=null;
public DatabaseConnection() throws Exception{
try{
Class.forName(DBDRIVER);
this.conn=DriverManager.getConnection(DBURL,DBUSER,DBPASSWARD);
}catch(Exception e){
throw e;
}
}
public Connection getConnection(){
return this.conn;
}
public void close() throws Exception{
if(this.conn!=null){
try{
this.conn.close();
}catch(Exception e){
throw e;
}
}
}
}
我一般都是這麼連接資料庫的 可能是你的語句順序問題吧
java連接MySQL資料庫報錯java.lang.ClassNotFoundException
你程序沒有放入這個數據連接的jar包吧!
方法1:放在jdk裡面lib包裡面,這個是普通的java項目
方法2:放在你的項目裡面,如web項目的話,項目就用引用的方式
希望能夠幫到你
java連接mysql資料庫報錯
樓上正解。
java.lang.Error: Unresolved compilation problem:
編譯錯誤,你的寫錯了。
原創文章,作者:UBPDQ,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/328922.html