java - Openshift - No suitable driver found for jdbc:mysql -
i new java , servlet programming. trying host simple application working in localhost. when host openshift, says no suitable driver found jdbc:mysql://127.12.204.2:3306/shifar
. want save string database. here code
import java.io.ioexception; import java.io.printwriter; import java.sql.connection; import java.sql.drivermanager; import java.sql.preparedstatement; import java.sql.sqlexception; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; public class testservlet extends httpservlet { private static final long serialversionuid = 1l; private static final string host = system.getenv("openshift_mysql_db_host"), port = system.getenv("openshift_mysql_db_port"), username = system.getenv("openshift_mysql_db_username"), password = system.getenv("openshift_mysql_db_password"), db_name = "shifar"; protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { string name = request.getparameter("username"); printwriter pw = response.getwriter(); try { class.forname("com.mysql.jdbc.driver"); } catch (classnotfoundexception e) { pw.println("error while loading driver: "+e.getmessage()); } try { string url = "jdbc:mysql://" + host + ":" + port + "/" + db_name; connection con = drivermanager.getconnection(url, username, password); preparedstatement prep = con.preparestatement("insert names (name) value (?)"); prep.setstring(1, name); int rc = prep.executeupdate(); pw.println("name saved !:"+name+" @ "+ rc); } catch (sqlexception e) { pw.println("error while connecting: "+e.getmessage()); } } }
i can't figure out error :(. deployment of application done through git
.war
live preview - (enter in edittext , submit)
your servlet container needs access jar file way. instance tomcat might want mysql-connector-java-5.1.35-bin.jar
in web-inf folder under application. need focus on classpath , setup of servlet container, regardless of is.
if need further assistance hang question under more details.
Comments
Post a Comment