在 Openshift 上部署战争文件后未找到合适的驱动程序错误
Posted
技术标签:
【中文标题】在 Openshift 上部署战争文件后未找到合适的驱动程序错误【英文标题】:No Suitable Driver Found Error after deploying a war file on Openshift 【发布时间】:2014-02-22 12:47:39 【问题描述】:大家好,我知道 openshift 线程的 No Suitable Driver Found Error
之前已经解决了,但是,after the multiple errors 当我从 eclipse(一个 maven 项目)部署一个项目时我得到了,我试图部署 war 文件(一个动态 web项目)在 webapp 文件夹上,然后只是 git add , commit 和 push 最后我让我的 servlet 运行但我无法与 mysql 数据库通信我已将 mysql_connector 添加到 web-inf/lib/ 文件夹但仍然没有!就像我说的那样,我在一个动态的 Web 项目上,所以我无法将依赖项添加到 pom.xml 文件中有人知道吗?
我的 java 文件:
import java.io.*;
//import java.util.*;
//import javax.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
//krijojme nje klase qe zgjaton superclassen HttpServlet
public class DBConnection extends HttpServlet
public static final String MYSQL_USERNAME = System.getenv("OPENSHIFT_MYSQL_DB_USERNAME");
public static final String MYSQL_PASSWORD = System.getenv("OPENSHIFT_MYSQL_DB_PASSWORD");
public static final String MYSQL_DATABASE_HOST = System.getenv("OPENSHIFT_MYSQL_DB_HOST");
public static final String MYSQL_DATABASE_PORT = System.getenv("OPENSHIFT_MYSQL_DB_PORT");
public static final String MYSQL_DATABASE_NAME = "jbossews";
/**
* kjo ketu nuk e di per cfare perdoret po duhet vene
*/
private static final long serialVersionUID = 1L;
//krijojme nje metode te klases HttpServlet me emrin service
//dhe qe merr 2 parametra nje reqyest dhe nje response
//si dhe hedh disa lloje gabimesh si psh input out exeption
//si dhe servlet Exception
public void service(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
//ketu tregon si do te jete pergjigja jone ne kete rast e duam html
response.setContentType("text/html");
//dhe fillojme te paraqisim
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Servlet JDBC</title></head>");
out.println("<body>");
out.println("<h1>Servlet JDBC</h1>");
out.println("</body></html>");
// connecting to database
//krijon ketu parametrat per tu lidhur me databasin
Connection con = null;
Statement st = null;
ResultSet rs = null;
try
try
Class.forName("com.mysql.jdbc.Driver");
catch (ClassNotFoundException cnfe)
out.println(cnfe);
String url = "mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/MYSQL_DATABASE_NAME";
con = DriverManager.getConnection(url, MYSQL_USERNAME, MYSQL_PASSWORD);
st = con.createStatement();
rs = st.executeQuery("SELECT * FROM servlet"); //shkruan queryn
// displaying records
while(rs.next()) //nderkohe qe ka te dhena nga query jone
out.print(rs.getObject(1).toString());
out.print("\t\t\t");
out.print(rs.getObject(2).toString());
out.print("<br>");
catch (SQLException ex)
out.println(ex);
finally
try
if (rs != null)
rs.close();
if (st != null)
st.close();
if (con != null)
con.close();
catch (SQLException ex)
out.println(ex);
P.s 我还必须补充一点,我已经在 localhost 上尝试过我的项目并且它有效
【问题讨论】:
【参考方案1】:网址不应该是这样的:
String url = "jdbc:mysql://" + MYSQL_DATABASE_HOST + ":" + MYSQL_DATABASE_PORT +
"/" + MYSQL_DATABASE_NAME;
即协议是"jdbc:mysql:"
并且参数不是(?)在字符串中自动替换...
【讨论】:
嗯....我很惭愧....谢谢你,这就是它所缺少的东西,也许我在这个项目上做了很多工作,我什至可以说出这么简单的事情,用大话来说谢谢你:)以上是关于在 Openshift 上部署战争文件后未找到合适的驱动程序错误的主要内容,如果未能解决你的问题,请参考以下文章