I have compiled my code using -cp <mysql-connector-java jar file>
. There were no errors during the compilation. All the class files were created
To run the code, I went to one directory higher and did java packagename.MyPgm
.
However, when i run this is the error that pops up:
Error in line no: -1 java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/feedback?user=root&password=passwd at java.sql.DriverManager.getConnection(DriverManager.java:640) at java.sql.DriverManager.getConnection(DriverManager.java:222) at javaapplication2.HttpHeaderParser.main(HttpHeaderParser.java:69)
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement;
import java.io.*;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
public class 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();
I've got some java String operations here. And then the catch statement.
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();
}