How to connect to Baidu Mysql
Use a mysql-connector-java-5.1.22.jar or an updated version.
Package org. crashxun. controller; import java. io. IOException; import java. SQL. connection; import java. SQL. driverManager; import java. SQL. resultSet; import java. SQL. statement; import javax. servlet. servletException; import javax. servlet. http. httpServlet; import javax. servlet. http. httpServletRequest; import javax. servlet. http. extends; public class MySQLBasic extends HttpServlet {@ Overrideprotected void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {Connection connection = null; Statement stmt = null; ResultSet rs = null; string SQL = null; try {/***** 1. enter database information (please refer to the database details page) *****/String databaseName = "eiZrxDYAgZRYcJuTRljT"; String host = "sqld.duapp.com"; String port = "4050 "; string username = "urtgxzmpvigneto3167yzg7c9"; // user name (api key); String password = "secret"; // password (secret // key) String driverName = "com. mysql. jdbc. driver "; String dbUrl =" jdbc: mysql: // "; String serverName = host +": "+ port +"/"; String connName = dbUrl + serverName + databaseName; /****** 2. connect to and select the database server named databaseName *****/Class. forName (driverName); connection = DriverManager. getConnection (connName, username, password); stmt = connection. createStatement ();/* now the connection has been fully established, you can perform corresponding operations on the current database * // * 3. next, you can use other standard mysql functions to perform database operations * // create a database table SQL = "create table if not exists test_mysql (" + "id int primary key auto_increment, "+" no int, "+" name varchar (1024), "+" key idx_no (no) ";stmt.exe cute (SQL);} catch (Exception e) {e. printStackTrace (resp. getWriter ());}}}