2、建立数据库:mysql>CREATE DATABASE 库名
3、建立数据表:mysql>USE 库名mysql>CREATE TABLE 表名 (字段名 VARCHAR(20), 字段名 CHAR(1))
4、删除数据库:mysql>DROP DATABASE 库名
5、删除数据表:mysql>DROP TABLE 表名;
6、将表中记录清空:mysql>DELETE FROM 表名
7、往表中插入记录:mysql>INSERT INTO 表名 VALUES ("hyq","M")
8、更新表中数据:mysql->UPDATE 表名 SET 字段名1='a',字段名2='b' WHERE 字段名3='c'
9、用文本方式将数据装入数据表中:mysql>load data local infile "d:/mysql.txt" into table 表名
读取数据库,首先要将数据库的驱动包导入:如果是mysql数据库,需要导入mysql-connector-java-5.1.27.jar,如果是oracle就需要导入oracle.jar包;然后就是建立数据库连接,使用Connection 新建连接,然后执行你的sql语句查询出需要的数据,下面是两个方法: public PageModel findAllUser(int pageNo,int pageSize){String sql = "select * from user where user_name <>'root' order by user_name" +"limit" + (pageNo - 1) * pageSize + "," + pageSizePageModel pageModel =nullConnection conn =nullStatement stmt =nullResultSet rs = nulltry{conn = DB.getConn()stmt = conn.createStatement()rs = stmt.executeQuery(sql)List user_List = new ArrayList()while(rs.next()){User user = new User()user.setUser_name(rs.getString("user_name"))user.setUser_password(rs.getString("user_password"))user.setUser_tel(rs.getString("user_tel"))user.setUser_email(rs.getString("user_email"))user.setUser_createDate(rs.getTimestamp("user_createdate"))user_List.add(user)}//取得所有记录int totalRecords = getTotalRecords(conn)pageModel = new PageModel()pageModel.setPageSize(pageSize)pageModel.setList(user_List)pageModel.setTotalRecord(totalRecords)}catch(SQLException e){e.printStackTrace()}finally{DB.close(rs)DB.close(stmt)DB.close(conn)}return pageModel} /** * 取得所有记录 * @param conn * @return 所有记录totalRecords */public int getTotalRecords(Connection conn){String sql = "select count(*) from user where user_name <>'root' "int totalRecords = 0Statement stmt = nullResultSet rs = nulltry{conn = DB.getConn()stmt = conn.createStatement()rs = stmt.executeQuery(sql)if(rs.next()){totalRecords = rs.getInt(1)}}catch(SQLException e){e.printStackTrace()}finally{DB.close(rs)DB.close(stmt)DB.close(conn)}return totalRecords}
1、链接数据库2、打开数据库链接3、读取数据记录比如ado的例子:Set Conn = New ADODB.Connection 数据库连接 Set Rec = New ADODB.Recordset 数据库记录Conn.Open "dsn=pic" 打开数据库链接
Rec.Open "pics", Conn, ad OpenDynamic, adLockOptimistic 读取数据库记录
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)