Я пытаюсь подключиться к базе данных MySql из сервлета Java. Я работаю в Eclipse IDE.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql//localhost:3306/try", "root", "password");
} catch (Exception e) {
e.printStackTrace();
}
if (request.getParameter("select1") != null) {
PrintWriter out = response.getWriter();
String select1 = (String) request.getParameter("select1");
int no = Integer.parseInt(select1);
String query = "SELECT * FROM try.try where id='" + no + "'";
out.print("<option>---select one---</option>");
try {
Statement stmt = (Statement) con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
out.print("<option>" + rs.getString("output") + "</option>");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
В строке
con = DriverManager.getConnection("jdbc:mysql//localhost:3306/try", "root", "password")
Я получаю следующее исключение:
java.sql.SQLException: No suitable driver found for jdbc:mysql//localhost:3306/try Exception.
Я скачал соединитель / J, извлек файл jar в папку библиотеки Tomcat и установил его в пути к классам.
Я понятия не имею, что еще я мог сделать неправильно. Там также написано
The JAR file C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\mysql-connector-java-5.1.18-bin.jar has no source attachment.
Заранее благодарю за любую помощь: -)