package MysqlTest;

import java.sql.DriverManager;
import java.sql.ResultSet; import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement; public class MysqlTest02 {
public static void main(String[] args) {
//连接url
String url = "jdbc:mysql://10.1.1.136:3306/JAVADB";
//连接driver
String driver = "com.mysql.jdbc.Driver";
//用户名
String name = "root";
//密码
String pwd = "root";
try{
Class.forName(driver);
Connection connection = (Connection) DriverManager.getConnection(url, name, pwd);
System.out.println("connection success"); //增添
// String sql ="insert into TEST(name,func) values(?,?)";
// PreparedStatement statement = (PreparedStatement) connection.prepareStatement(sql);
// statement.setObject(1,"高文斌");
// statement.setObject(2,"准备找工作");
// int result = statement.executeUpdate();
// if (result == 1){
// System.out.println("插入成功");
// }
// connection.commit(); //查询
// String sql1 = "select * from TEST WHERE ID > ?";
// PreparedStatement sta1 = (PreparedStatement) connection.prepareStatement(sql1);
// sta1.setInt(1, 1);
// ResultSet re = sta1.executeQuery();
// while (re.next()){
// String names = re.getString(2);
// String func = re.getString(3);
// System.out.println(names+"\t:"+func);
// }
// System.out.println("查询完毕"); // //删除
// String ddl = "delete from TEST where name = '高文斌'";
// Statement sta = (Statement) connection.createStatement();
// int eff = sta.executeUpdate(ddl);
// System.out.println(eff); //更改
Statement s = (Statement) connection.createStatement();
int b = s.executeUpdate("update TEST set name='周文王' where name='李四'");
System.out.println(b);
}catch (Exception e) {
System.out.println(e);
}
}
}

  

准备工作:

  1.下载mysql-connector-java-5.1.45.zip包到本地

  2.配置好远程数据库配置文件,我的是在虚拟机上模仿的,文件位置在/etc/mysql/mysql.conf.d/mysqld.cnf,找到bind-address = 127.0.0.1注释掉,允许远程访问

最新文章

  1. python中单引号, 双引号,三引号的差异
  2. NodeJS入门(四)—— path对象
  3. Solr嵌套子文档的弊端以及一种替代方式
  4. Windows下 VM12虚拟机安装OS X 10.11 和VM TOOLS
  5. win7下IIS配置以及域名映射方法
  6. linux之iptables
  7. 使用Jsoup 抓取页面的数据
  8. Linux C 创建目录函数mkdir相关(转-清新居士)
  9. POJ C程序设计进阶 编程题#1:单词翻转
  10. ECshop 在迁移到 PHP7 时遇到的兼容性问题
  11. Css3案例
  12. HDU 1248 寒冰王座(全然背包:入门题)
  13. java MD5加密
  14. CI 模板解析器类
  15. 使用Webbrowser的一点心得体会
  16. 使用keepalived使用主备热备份功能
  17. vue2.0 子组件和父组件之间的传值(转载)
  18. CASE WHEN 及 SELECT CASE WHEN的用法
  19. day14 python各种推导式详解
  20. 011-MAC 设置环境变量path的几种方法

热门文章

  1. Struts多个文件上传
  2. malloc、calloc、realloc和alloca各种的区别
  3. HDU4990 Reading comprehension —— 递推、矩阵快速幂
  4. 值域线段树 bzoj 4627
  5. hdu-5621 KK's Point(dp+数学)
  6. C语言中文件操作
  7. MAC 地址解析
  8. vim 使用、设置笔记
  9. telnet命令发送邮件
  10. rsync(五)工作机制