我的代码存在以下问题:
import java.sql.*;
public class App {
public static void main(String[] args){
String url = "jdbc:mysql://localhost:3306" ;
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e)
{ System.out.println("Eroare incarcare driver!\n" + e);
return;
}
try{
Connection con = DriverManager.getConnection(url);
// Golim tabelul persoane
String sql = "DELETE FROM persoane";
Statement stmt = con.createStatement();
stmt.executeUpdate(sql);
stmt.execute("CREATE DATABASE IF NOT EXISTS test");
stmt.execute("USE test");
我得到了例外......任何想法我怎么能做到这一点? THX。
enter code here
答案 0 :(得分:2)
您需要下载jdbc连接器并将其添加到类路径中。
答案 1 :(得分:1)
更改
Connection con = DriverManager.getConnection(url);
到
Connection con = DriverManager.getConnection(url,"username","password");
并将其替换为您的username
和password
答案 2 :(得分:1)
确保您的应用程序classpath.
上有MySQL驱动程序答案 3 :(得分:1)