String driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://127.0.0.1:3306/phpdb"; String u = "root"; String p = "sa123456"; try { Class.forName(driver); Connection con = DriverManager.getConnection(url,u,p); if(!con.isClosed()){ System.out.println("链接成功..."); Statement statement = con.createStatement(); String sql = "select * from articles"; String insertSql = "insert into articles(title,content) values(?,?)"; //执行查询操作 ResultSet rs = statement.executeQuery(sql); PreparedStatement ps = con.prepareStatement(insertSql); ps.setString(1, "哈哈哈1111"); ps.setString(2, "写入数据成功啦...."); //执行增、删、改操作 ps.executeUpdate(); while(rs.next()){ System.out.println(rs.getString("content")); } rs.close(); con.close(); } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }