Pessoal, preciso muito de ajuda, pois agora buguei o cérebro...
Eu tenho este código pra abrir uma conexão no mysql
package br.com.rlbc.DAO;
import java.sql.DriverManager;
import java.sql.SQLException;
import com.mysql.jdbc.Connection;
public class DataBase {
private String url;
private String user;
private String password;
public DataBase() {
url = "jdbc:mysql://rocket-league.mysql.uhserver.com/rocket_league";
user = ""; //removido apenas aqui no alura
password = ""; //removido apenas aqui no alura
}
public Connection getConnection() {
Connection connection = null;
try {
connection = (Connection) DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
}
E tenho esta classe para consulta
package br.com.rlbc;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import com.mysql.jdbc.Connection;
import br.com.rlbc.DAO.DataBase;
import br.com.rlbc.redirects.Time;
public class CampeonatosDAO {
private Connection con;
public CampeonatosDAO() {
this.con = new DataBase().getConnection();
}
public LinkedList<Time> getTimes(String campName) {
String sql = "Select * from CAMPEONATOS where campeonato = ?";
try (PreparedStatement stmt = con.prepareStatement(sql)) {
stmt.setString(1, campName);
stmt.execute();
try (ResultSet resultSet = stmt.getResultSet()) {
LinkedList<Time> times = new LinkedList<>();
while (resultSet.next()) {
times.add(new Time(resultSet.getString("time")));
}
return times;
}
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
}
Eu criei esta classe de teste que funciona normalmente...
package br.com.rlbc;
import java.util.LinkedList;
import br.com.rlbc.redirects.Time;
public class TestaCampeonato {
public static void main(String[] args) {
LinkedList<Time> times = new CampeonatosDAO().getTimes("2v2free");
for (Time time : times) {
System.out.println(time);
}
}
}
Mas quando eu tento acessar através da URI
package br.com.rlbc.redirects;
import java.io.IOException;
import java.util.LinkedList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import br.com.rlbc.CampeonatosDAO;
@WebServlet(urlPatterns="/informacoes")
public class Informacoes extends HttpServlet{
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String parameter = req.getParameter("camp");
RequestDispatcher dispatcher = null;
if (parameter.equals("2v2premium")) {
dispatcher = req.getRequestDispatcher("/WEB-INF/jsp/2v2premium.jsp");
} else if (parameter.equals("2v2free")) {
LinkedList<Time> times = new CampeonatosDAO().getTimes("2v2free");
dispatcher = req.getRequestDispatcher("/WEB-INF/jsp/2v2free.jsp");
} else if (parameter.equals("2v2chave")) {
dispatcher = req.getRequestDispatcher("/WEB-INF/jsp/2v2chave.jsp");
}
dispatcher.forward(req, resp);
}
}
Encontro o seguinte problema:
java.sql.SQLException: No suitable driver found for jdbc:mysql://rocket-league.mysql.uhserver.com/rocket_league
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at br.com.rlbc.DAO.DataBase.getConnection(DataBase.java:23)
at br.com.rlbc.CampeonatosDAO.<init>(CampeonatosDAO.java:18)
at br.com.rlbc.redirects.Informacoes.doGet(Informacoes.java:28)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
set 25, 2016 3:55:39 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [br.com.rlbc.redirects.Informacoes] in context with path [] threw exception