java - Driver for jdbc not found (only on servlet) -
i have problem connecting mysql databse servlet. here 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 jdbc:mysql://localhost/database?userinfo sqlstate: 08001 vendorerror: 0
i put mysql-connector-java-5.1.27-bin in webapps\web-inf\lib , apache-tomcat-7.0.55\lib
and it's still same. in desktop version of application works fine. it's happening on servlet.
the basic problem
your first step should registering driver using this
class.forname("com.mysql.jdbc.driver");
then try connection drivermanager using this
conn = drivermanager.getconnection(url);
i guess doing reverse way
Comments
Post a Comment