LoginAuthServlet.java
Class.forName("com.mysql.jdbc.GoogleDriver");
String url="jdbc:google:mysql://Instance_connection_name/dbname?user=xyz&password=abc";
Connection conn = DriverManager.getConnection(url);
String query = "SELECT "
+ " * "
+ " FROM "
+ " users "
+ " WHERE "
+ " user_username = ? AND user_password = ? AND user_status = '1' "
/*+ " user_type = ? "*/
+ " limit 0,1";
PreparedStatement stmtLogin = conn.prepareStatement(query);
stmtLogin.setString(1, username);
stmtLogin.setString(2, userPassword);
ResultSet resource = stmtLogin.executeQuery();
if(resource.next()){
HttpSession sess = req.getSession();
sess.setAttribute("isLogin", "true");
sess.setAttribute("userId", resource.getString("user_id"));
sess.setAttribute("userName", resource.getString("user_username"));
sess.setAttribute("userType", resource.getString("user_type"));
sess.setMaxInactiveInterval(30*60);
resp.sendRedirect("BusinessList.jsp");
}
appengine-web.xml
<use-google-connector-j>true</use-google-connector-j>
When i deploy this project and attempt to login then give response is {}..... i included all the jar file and if i am try to connect locally with IPV4 address then it work well,but if i deploy project then it's not work,i done all the things but my project can't connect with google cloud sql.
If you are using a second generation instance, in order to connect from appengine you also need to include the region JDBC url like below:
String url="jdbc:google:mysql://[PROJECT-ID]:[REGION]:[INSTANCE-NAME]/dbname?user=xyz&password=abc";
Here they provide some example: https://cloud.google.com/appengine/docs/java/cloud-sql/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.