For some reason, NetBeans keep on telling me that there are incompatibilities between the Connection and DriverManager return value... I've been looking through Google and weren't able to find the solution.. People keep on saying that this is the way, but in fact NetBeans says that it's incompatible types..
I've imported the MySQL connector library to the project in Netbeans..
Here's the code snippet:
PHP Code:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String username = request.getParameter("username");
String password = request.getParameter("password");
Connection con = null;
try {
String dbuser = "dbuser";
String dbpass = "dbpass";
String url = "jdbc:mysql://localhost/socialnetworking";
Class.forName ("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(url, dbuser, dbpass); // error is here
/********************
NetBeans message:
incompatible types
found: java.sql.Connection
required: com.mysql.jdbc.Connection
*******************/
System.out.println ("Database connection established");
} catch (Exception e) {
}
out.flush();
out.close();
}
Here's some import statements:
PHP Code:
import com.mysql.jdbc.Connection;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.DriverManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
I was thinking that the DriverManager is returning Microsoft SQL server type, and the Connection is MySQL JDBC connection type, but I've no clue how to resolve this...
Thanks a lot for the help!!!