视频地址:http://www.tudou.com/programs/view/4GIENz1qdp0/
新建BaseDao
package cn.wingfly.dao; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class BaseDao { Connection con = null; Statement st = null; ResultSet rs = null; /** * 获得联接 * * @return */ public Connection getConnection() { try { // 加载驱动,这一句也可写为:Class.forName("com.mysql.jdbc.Driver"); Class.forName("com.mysql.jdbc.Driver").newInstance(); // 建立到MySQL的连接 con = DriverManager.getConnection("jdbc:mysql://localhost:3306/money_note?characterEncoding=UTF-8", "root", "root"); } catch (Exception e) { e.printStackTrace(); } return con; } /** * 关闭数据源 */ public void CloseConnection(Connection con, Statement s, ResultSet rs) { try { if (rs != null) { rs.close(); } if (s != null) { s.close(); } if (con != null) { con.close(); } } catch (SQLException e) { e.printStackTrace(); } } }测试类
package cn.wingfly.dao; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Test extends BaseDao { Connection con = null; Statement st = null; ResultSet rs = null; /** * 查询数据 */ public void find() { con = getConnection(); // 获得联接 try { st = con.createStatement(); rs = st.executeQuery("select * from app_user"); while (rs.next()) { System.out.println("编号:" + rs.getInt("uuid") + ", 姓名:" + rs.getString("userName") + ", 性别:" + rs.getString("sex") + ", 生日:" + rs.getString("birthday") + ", 住址:" + rs.getString("address")); } } catch (SQLException e) { e.printStackTrace(); } finally { CloseConnection(con, st, rs); // 关闭联接 } } /** * 添加数据 */ public void add() { con = getConnection(); try { st = con.createStatement(); int result = st.executeUpdate("insert into app_user(userName,passWord,sex,birthday,address) values('赵丽颖','wanying','女','1992-02-03','北京市')"); if (result > 0) { System.out.println("插入成功"); } else { System.out.println("插入失败"); } } catch (SQLException e) { System.out.println("插入失败"); e.printStackTrace(); } finally { CloseConnection(con, st, rs); } } /** * 更新数据 */ public void update() { con = getConnection(); try { st = con.createStatement(); int result = st.executeUpdate("update app_user set address = '河南' where uuid = '3'"); if (result > 0) { System.out.println("更新成功"); } else { System.out.println("更新失败"); } } catch (SQLException e) { e.printStackTrace(); } finally { CloseConnection(con, st, rs); } } /** * 删除数据 */ public void delete() { con = getConnection(); try { st = con.createStatement(); int result = st.executeUpdate("delete from app_user where uuid = '3'"); if (result > 0) { System.out.println("删除成功"); } else { System.out.println("删除失败"); } } catch (SQLException e) { e.printStackTrace(); } finally { CloseConnection(con, st, rs); } } public static void main(String[] args) { Test test = new Test(); //test.add(); // test.update(); test.delete(); test.find(); } }

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version
SublimeText3 Linux latest version

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool