Mysql接口实现类:mysql-connector-java-5.1.6-bin.jar 提取码:4088
实现代码:
public class database { public static void main(String[] args) throws Exception { //数据库地址url: String url = "jdbc:mysql://localhost:3306/atashopping"; //sql命令: String sql ="insert into bank(cardname,password,money)values('王老板','1234',100000)"; //将Mysql服务器提供的jar包中的Drvier接口实现类,注册到JVM: Driver drvier = new com.mysql.jdbc.Driver(); DriverManager.registerDriver(drvier); //通过DriverManager在Java工程和mysql服务器之间建立一个连接通道con: Connection con = DriverManager.getConnection(url,"root","123456"); //在通道上建立数据运输工具ps: PreparedStatement pr = con.prepareStatement(""); //将sql命令带到Mysql服务器中并带回执行结果: int result = pr.executeUpdate(sql); //销毁相关资源: if(pr != null) pr.close(); if(con!=null) con.close(); System.out.println("对表操作成功,操作了 "+result+" 行数据"); } }