gpt4 book ai didi

java - 为什么我没有找到适合 jdbc 的驱动程序 :derby://localhost:1527/employee;create=true error in my code?

转载 作者:行者123 更新时间:2023-12-02 05:03:51 24 4
gpt4 key购买 nike

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/


package database_console;

/**
*
* @author nareshreddy
*/

//import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;


public class DBConnect {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try{


String host = "jdbc:derby://localhost:1527/employee;create=true";
String uName = "root";
String uPass = "14mcmi34";

Connection con = DriverManager.getConnection( host, uName,uPass );

Statement stmt = con.createStatement( );

String SQL = "SELECT * FROM WORKERS";
ResultSet rs = stmt.executeQuery( SQL );

while( rs.next( ) ) {
int id_col = rs.getInt("ID");
String first_name = rs.getString("First_Name");
String last_name = rs.getString("Last_Name");
String job = rs.getString("Job_Title");

String p = "id_col + \" \" + first_name + \" \" + last_name + \" \" + job";

System.out.println(p);
}
}
catch ( SQLException err ) {
System.out.println( err.getMessage( ) );
}


}

}

我得到了“没有找到适合 jdbc 的驱动程序:derby://localhost:1527/employee;create=true ”错误为什么?添加我的“/home/nareshreddy/HARDDISK/2nd Sem/SE lab/java program/java Jar file/mysql-connector-java-5.0.8/mysql-connector-java-5.0.8-bin.jar ”文件后

最佳答案

您的连接字符串需要 derby DB 驱动程序,而不是 mysql 连接器。所以下载Driver对于 Derby DB 并将其添加到类路径中,或者如果您想使用 mysql,则必须将连接字符串更改为 jdbc:mysql://...

关于java - 为什么我没有找到适合 jdbc 的驱动程序 :derby://localhost:1527/employee;create=true error in my code?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27990919/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com