做淘宝客网站教程,蕲春做网站,千卓品牌策划,网页版微信无法登陆JDBC简介JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API#xff0c;可以为多种关系数据库提供统一访问#xff0c;它由一组用Java语言编写的类和接口组成。本文中中使用的数据库数据库软件#xff1a;MySQL5.6数据库#xff1a;test表可以为多种关系数据库提供统一访问它由一组用Java语言编写的类和接口组成。本文中中使用的数据库数据库软件MySQL5.6数据库test表student其表结构如下------------------------------------------------------| Field | Type | Null | Key | Default | Extra |------------------------------------------------------| id | int(11) | NO | PRI | 0 | || name | varchar(20) | YES | | NULL | || english | float | YES | | NULL | || math | float | YES | | NULL | || birthday | date | YES | | NULL | || native_place | varchar(30) | YES | | NULL | || chinese | int(11) | YES | | NULL | |------------------------------------------------------| student | CREATE TABLE student (id int(11) NOT NULL DEFAULT 0,name varchar(20) DEFAULT NULL,english float DEFAULT NULL,math float DEFAULT NULL,birthday date DEFAULT NULL,native_place varchar(30) DEFAULT NUchinese int(11) DEFAULT NULL,PRIMARY KEY (id)) ENGINEInnoDB DEFAULT CHARSETutf8 |JDBC的使用建立连接建立链接总共3中方式static Connection getConnection(String url)static Connection getConnection(String url, Properties info)static Connection getConnection(String url, String user, String password)本文中将使用第3中方式。Connection connnull;try{connDriverManager.getConnection(url_conn, user_conn, passwd_conn);}catch(SQLException e) {e.printStackTrace();}获取statementStatement stnull;try{stconn.createStatement();}catch(SQLException e) {e.printStackTrace();}执行SQL语句1-查询2-插入3-删除4-修改下面为查询的示例String sql_query_all_studnetselect * from student;ResultSet resnull;try{resst.executeQuery(sql_query_all_studnet);}catch(SQLException e) {e.printStackTrace();}try{System.out.println(id\tname\tchinese\tmath\tenglish);while(res.next()){int idres.getInt(id);String nameres.getString(name);int chineseres.getInt(chinese);double mathres.getDouble(math);double englishres.getDouble(english);System.out.println(id\tname\tchinese\tmath\tenglish);}}catch(SQLException e) {e.printStackTrace();}结果id name chinese math english1 潘怡茹 97 91.0 86.02 刘濮松 96 68.0 88.03 刘吉如 70 53.0 85.04 李岩珂 96 70.0 85.05 王晓博 46 79.0 85.06 李帅旭 97 76.0 79.07 李静瑶 92 61.0 89.08 金纾凡 83 43.0 80.09 秦梓航 86 46.0 57.010 关颖利 84 77.0 80.0关闭连接try{st.close();}catch(SQLException e) {e.printStackTrace();}try{conn.close();}catch(SQLException e) {e.printStackTrace();}