We can use Speedamp to build a server environment that can be downloaded in http://download.csdn.net/detail/baidu_nod/7630265
No installation can be used directly after decompression, click SpeedAMP.exe, then you can access the local database via http://localhost/phpmyadmin/index.php
Java can access the database through JDBC, it is more important to download a Mysql-connector-java-5.1.22-bin.jar file, and then reference in the Java project,
In the code you can visit:
Import java.sql.*;p Ublic class Conntest {public static final string _id = ' _id '; public static final String table_name = "Spider"; public static final String name = "Name"; public static final String class_name = "CLASS"; private static final String create_table_stmt = "CREATE TABLE IF not EXISTS" + table_name + "(" + _i D + "INTEGER PRIMARY KEY," + NAME + "text," + class_name+ "text" + ");"; public static void Main (string[] args) {Java.sql.Connection conn = null; Statement st = null; ResultSet rs = null;try {class.forname ("com.mysql.jdbc.Driver");//load JAR Package conn = drivermanager.getconnection ("JDBC: Mysql://localhost:3306/test?useunicode=true&characterencoding=utf8 "," Root "," ");//Get database connection//This is to create a table St = Conn.createstatement (); St.execute (create_table_stmt);//This is inserting a statement//st = Conn.createstatement ();//string sql = "Insert Into Spider (_id,name,class) VALUES (' 1 ', ' xiaoming ', ' A '),//st.executeupdate (SQL);//This is an INSERT statement with PreparedStatement implementation String sqL = "INSERT into spider (_id,name,class) VALUES (?,?,?)"; /preparedstatement _prepinsert = conn.preparestatement (sql)//_prepinsert.setint (1, 2);//_prepinsert.setstring (2, " Xiaoli ");//_prepinsert.setstring (3," B ");//_prepinsert.executeupdate ();////This is an UPDATE statement//st = Conn.createstatement () ;//string sql = "Update spider set class = ' C ' where _id = ' 1 '";//st.executeupdate (sql);////This is a DELETE statement//st = Conn.createstat Ement ();//string sql = "Delete from spider where _id = ' 1 '";//st.executeupdate (sql);//This is the query statement st = Conn.createstatement (); String sql = "SELECT * from Spider", rs = st.executequery (sql), while (Rs.next ()) {int id = rs.getint ("_id"); String name = rs.getstring ("name"); String Class1 = rs.getstring ("class"); System.out.println ("id=" +id+ "name=" +name+ "class1=" +class1);}} catch (Exception e) {e.printstacktrace ();} if (rs! = null) {try {rs.close ();} catch (SQLException e) {e.printstacktrace ()}} if (st! = null) {try {st.close ();} catch (SQLException e) {e.printstacktrace ();}} IF (conn! = null) {try {conn.close ();} catch (SQLException e) {e.printstacktrace ();}}}}
We can exercise this way to write SQL statements