有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java错误:在AWS 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

请帮忙

先谢谢你


共 (1) 个答案

  1. # 1 楼答案

    你的这一行似乎不正确

    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"