The Bae database uses MySQL and phpMyAdmin. How can this problem be solved? It is too much like the PHP space.
But they are all free ~~
The first problem is data connection.
I made a simple chat room project and planned to try it out.
The user name and password of the BAE database connection must be obtained from the request.
Only the database name can be used directly.
Defines a jdbcutil class. Used to obtain the connection.
To save code, you can directly write a total of static variables.
Public final class jdbcutil {Private Static string dburl = "JDBC: mysql: //"; public static string port; public static string host; public static string username; public static string password; public static string databasename = "zjtjktokkluogqqzmbkc"; // reject the private jdbcutil () {}; static {// register the driver try {class. forname ("com. mySQL. JDBC. driver ");} catch (classnotfoundexception e) {Throw new exceptionininitializererror (e) ;}} public static connection getconnection () throws sqlexception {string connname = dburl + host + ": "+ port +"/"+ databasename; return drivermanager. getconnection (connname );}
To access each page, you must set the connection user name and password.
Simply use a filter to filter each request.
<filter><filter-name>jdbc</filter-name><filter-class>filter.InitFilter</filter-class></filter><filter-mapping><filter-name>jdbc</filter-name><url-pattern>*.*</url-pattern></filter-mapping>
public class InitFilter implements Filter{public void destroy() {}public void doFilter(ServletRequest req, ServletResponse response,FilterChain chain) throws IOException, ServletException {HttpServletRequest request = (HttpServletRequest)req;JdbcUtil.host = request.getHeader("BAE_ENV_ADDR_SQL_IP");JdbcUtil.port =request.getHeader("BAE_ENV_ADDR_SQL_PORT");JdbcUtil.username = request.getHeader("BAE_ENV_AK");JdbcUtil.password = request.getHeader("BAE_ENV_SK");chain.doFilter(request, response);}public void init(FilterConfig arg0) throws ServletException {}}