java - 错误 : No suitable driver found for database on AWS RDS

标签 java mysql jdbc connection amazon-rds

我的代码如下,我在 AWS RDS 上有一个 MySQL 数据库。我还已经在构建路径中包含了 mysql-connector-java-5.1.31-bin.jar。 我的代码如下:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"     "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*"%>
<%@ page import="java.util.Scanner "%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome Customer to Online Mall</title>
</head>
<body>
<%      
 final String host = "jdbc:mysql://mySqlPath/ShopSystem";
 final String uName = "myusername";
 final String uPass = "mypassword";
 try
 {
 Class.forName("com.mysql.jdbc.Driver").newInstance();

 //@SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    String Cust_address, Cust_email, Cust_contact;
    Connection con = DriverManager.getConnection( host, uName, uPass );     
    //View all shops
    Statement stmt5 = con.createStatement();
 ResultSet rs2 = stmt5.executeQuery("SELECT * FROM ShopSystem.Shop");
    while(rs2.next())
    {   
                System.out.print("s_id = "+rs2.getInt(1)+"\t");
                System.out.print("s_name = "+rs2.getString(4)+"\t");                    
                System.out.print("s_location = "+rs2.getString(3)+"\t");                    
                System.out.println();           
     }              
sc.close();
 }
 catch(SQLException err)
    {
        System.out.println(err.getMessage());
    }       

%>   
</body>
</html>

我收到以下错误:

Aug 01, 2014 5:31:46 PM org.apache.jasper.compiler.Compiler removeGeneratedFiles
WARNING: Failed to delete generated Java file     [C:\Users\Documents\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\local    host\ShopSystem-AWSJavaWebProject\org\apache\jsp\WelcomeCustomer_jsp.java] 
No suitable driver found for jdbc:mysql://mySqlPath/ShopSystem

请帮忙。

提前谢谢你。

最佳答案

您的这一行似乎不正确。

final String host = "jdbc:mysql://mySqlPath/ShopSystem";

应该是这样的:

jdbc:mysql://localhost/ShopSystem

jdbc:mysql://{YOUR_IP}/ShopSystem    // e.g. "jdbc:mysql://192.168.15.102/ShopSystem"

关于java - 错误 : No suitable driver found for database on AWS RDS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25080148/

相关文章:

java - Spring - 在不同的 web 应用程序之间共享 web 应用程序上下文

java - 问 : Help understanding closing Scanner

Java/MySQL - 如何从另一个类访问连接?

Java Hive 连接executeUpdate() 始终返回计数为零

php - 从一个php脚本获取变量到另一个php脚本

java - 为什么 select 语句总是返回最后插入的值?

java - 按金额删除购物车中的产品

java - java中可以使用空闲线程同时执行其他线程的工作吗?

php - 多个 url 链接变量

mysql - 如何列出每个国家/地区的订单数量以及国家/地区名称?