jeudi 29 janvier 2015

Connecting to MySQL Database - GAE - AWS - Maven

I am receiving data in a Java Servlet (maven) and want to store it in a MySQL database that is hosted at Amazon. The application is hosted at Google.


I receive the error message "no suitable driver found for..."


I already added the mysql-connector-java-5.1.18-bin.jar to the folder WEB-INF/lib


This is my code:



package com.example.mail;

import java.io.IOException;
import java.util.Properties;
import javax.mail.Session;
import javax.mail.internet.MimeMessage;
import javax.servlet.http.*;
import javax.mail.Address;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Logger;

public class MailHandlerServlet extends HttpServlet {
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);

try{
MimeMessage message = new MimeMessage(session, req.getInputStream());
String summary = message.getSubject();
Address[] addresses = message.getFrom();
String text = message.getContent().toString();
System.out.println("Subject: " + summary);
System.out.println("Sender: " + addresses);
System.out.println("Text: " + text);

} catch (Exception e) {
e.printStackTrace();
}

String connectionUrl = "jdbc:http://mysqlaws-address:port/table";
String dbUser = "user";
String dbPwd = "pw";
Connection conn = null;

try {
conn = (Connection) DriverManager.getConnection(connectionUrl, dbUser, dbPwd);
System.out.println("conn Available");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("fetch otion error"+e.getLocalizedMessage());
}
}
}


Thank you for your help!





Aucun commentaire:

Enregistrer un commentaire