No suitable driver found [duplicate]-Collection of common programming errors
i am trying to get a connection with my database but i get the following error:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/sondazh
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at admin.ConnectionManager.openConnection(ConnectionManager.java:31)
at admin.ConnectionManager.getConnection(ConnectionManager.java:44)
at admin.DatabaseObject.(DatabaseObject.java:12)
at org.apache.jsp.test_jsp._jspService(test_jsp.java:85)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
null
i have created a code in java for connection with mysql database.
package admin;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionManager {
private static ConnectionManager instance = null;
private static final String USERNAME = "root";
private static final String PASSWORD = "";
private static final String CONN_STRING =
"jdbc:mysql://localhost/sondazh";
private Connection conn = null;
private ConnectionManager() {
}
public static ConnectionManager getInstance() {
if (instance == null) {
instance = new ConnectionManager();
}
return instance;
}
private boolean openConnection() {
try {
conn = DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
return true;
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
public Connection getConnection() {
if (conn == null) {
try {
if (openConnection()) {
return conn;
} else {
return null;
}
} catch (Exception e) {
// TODO Auto-generated catch block
throw new Error(e);
}
}
return conn;
}
public void close() {
try {
conn.close();
conn = null;
} catch (Exception e) {
}
}
}
i also searched in google for that prob but the URL is ok and i dont know what may be the problem!
Originally posted 2013-11-09 23:31:35.