I have a problem connecting to MySQL databse from servlet. Here is my connection code
private static void connectToDatabase(){
try{
static Connection conn = null;
static String url = "jdbc:mysql://localhost/database?userinfo";
conn = DriverManager.getConnection(url);
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connected");
} catch(ClassNotFoundException wyjatek) {
System.out.println("Problem ze sterownikiem");
} catch(SQLException wyjatek) {
System.out.println("SQLException: " + wyjatek.getMessage());
System.out.println("SQLState: " + wyjatek.getSQLState());
System.out.println("VendorError: " + wyjatek.getErrorCode());
}
}
and doGet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
String param = request.getParameter("lookFor");
out.println("TEST");
connectToDatabase();
}
and everytime I'm getting this
SQLException: No suitable driver found for jdbc:mysql://localhost/database?userinfo
SQLState: 08001
VendorError: 0
I put the mysql-connector-java-5.1.27-bin in webapps\WEB-INF\lib and apache-tomcat-7.0.55\lib
and it's still the same. In the desktop version of application everything works fine. It's happening only on servlet.
Class.forName("com.mysql.jdbc.Driver")
before callingDriverManager.getConnection(url)
? – Jack