JDBC 常用 备忘录

JDBC  

jdbc utils封装的内容

在静态代码块中 执行  DRIVER的加载

class.forName("com.mysql.jdbc.Driver");

四个私有变量;当数据库不一样时 需要修改;

private static final String username = "root";
private static final String password = "root";
private static final String url = "jdbc:mysql://localhost/mysql?seUnicode=true&characterEncoding=UTF8";
private static final String drivername = "com.mysql.jdbc.Driver";

然后封装了executeQuery(Connection conn,String sql,Object...parameters)/executeQuery(sql,parameters)

     executeUpdate(Connection conn,String sql,Object...parameters)/executeUpdate(sql,parameters)

以及相应的close(conn/rs)的方法;

 

 

 

SQL 增 删 改 查 子句

select * from 表名

select name from 表名 where 条件语句 name=value

insert into 表名 (属性名1,属性名2...) values(属性值1,属性值2...);

Update 表名 set name=value ,name2=value2... where 条件语句;

delete from table where name=value     

 

//mysql数据库查询总数方法可以是select count(*)  from table(表名字);
总数:select count as totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1


http://www.cnblogs.com/cunkouzh/p/5588319.html

 

posted on 2017-08-30 21:45  小丰残月  阅读(97)  评论(0编辑  收藏  举报

导航