【发布时间】:2013-04-14 23:39:28
【问题描述】:
我已经使用-cp <mysql-connector-java jar file> 编译了我的代码。编译过程中没有错误。所有类文件都已创建
为了运行代码,我转到更高的一个目录并执行java packagename.MyPgm。
但是,当我运行这是弹出的错误:
行号错误:-1
java.sql.SQLException:找不到适合 jdbc 的驱动程序:mysql://localhost/feedback?user=root&password=passwd
在 java.sql.DriverManager.getConnection(DriverManager.java:640)
在 java.sql.DriverManager.getConnection(DriverManager.java:222)
在 javaapplication2.HttpHeaderParser.main(HttpHeaderParser.java:69)
导入 com.mysql.jdbc.Connection;
导入com.mysql.jdbc.PreparedStatement;
导入com.mysql.jdbc.Statement;
导入 java.io.*;
导入java.sql.DriverManager;
导入 java.sql.SQLException;
导入java.util.ArrayList;
公共类 HttpHeaderParser {
static Connection connect = null;
static Statement statement = null;
public static void main(String[] args) throws IOException {
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader(new File("http_headers.txt")));
FirstLine firstObj = null;
SecondLine secondObj;
OtherFields otherObj;
connect = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/feedback?"+"user=root&password=sicily"); //this will connect to the database
statement = (Statement) connect.createStatement();
我这里有一些 java 字符串操作。然后是 catch 语句。
catch (Exception e) {
System.out.println("Error in line no: "+lineCount); //displays the line number of the input file where the program stopped
e.printStackTrace();
}
【问题讨论】:
-
程序语法正确。问题出现在运行时。 DriverManager 在运行时无法获取或找到实例。
-
这是您获得的完整堆栈跟踪吗?
-
是的,这就是我所得到的。
-
通过包含您使用的代码来编辑您的问题。
-
你去。请看一看。
标签: java mysql linux jdbc terminal