Last active
November 20, 2019 05:59
-
-
Save MrFant/20a15fc3f70236ed51fcba3fba037aee to your computer and use it in GitHub Desktop.
Revisions
-
MrFant revised this gist
Nov 20, 2019 . 1 changed file with 40 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ import java.sql.*; public class jdbc{ public static void main(String[] args) throws Exception { //1、注册驱动,什么是驱动?能够让java连接数据库,也就是实现jdbc接口规范就是驱动 Class.forName("com.mysql.jdbc.Driver");//硬编码 /* * 2、通过驱动管理者获取数据库连接 * DriverManager是驱动实现类的管理者。 * url:连接数据库的位置,端口号,数据库名 * jdbc:mysql://localhost:3306/test_01 */ try(Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mybatis", "root", "root")){ /* * 3、获得sql语句执行者 * statement:执行sql语句对象 * sql语句必须是完整的。 * preparedStatement:预处理(常用) * sql语句可以不是完整的,可以将参数用?替代,然后在预编译后加入未知参数 * */ //定义sql语句,?表示占位符 String sql = "select * from student where id = ?"; //硬编码 try(PreparedStatement ps = conn.prepareStatement(sql)){ ps.setInt(1, 1); //硬编码 //4、获取sql语句执行结果,resultset /* * executeQuery():查询操作 * executeUpdate():增删改操作 */ try(ResultSet rs= ps.executeQuery()){ //5、处理结果 while(rs.next()){ System.out.println(rs.getString(3));;//index代表第几列,从1开始 } } } } } } -
MrFant revised this gist
Nov 20, 2019 . No changes.There are no files selected for viewing
-
MrFant revised this gist
Dec 5, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,6 +22,7 @@ public static void main(String[] args) throws Exception{ //定义sql语句,?表示占位符 String sql = "select * from user where id = ?"; //硬编码 PreparedStatement ps = conn.prepareStatement(sql); // 设置第一个参数值为int类型的1,后面那个1是index,从1开始,不是从0开始。 ps.setInt(1, 1); //硬编码 //4、获取sql语句执行结果,resultset /* -
MrFant revised this gist
Dec 5, 2018 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ // 依赖jdbc import java.sql.*; public class jdbc{ public static void main(String[] args) throws Exception{ //1、注册驱动,什么是驱动?能够让java连接数据库,也就是实现jdbc接口规范就是驱动 -
MrFant revised this gist
Dec 5, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ public class jdbc{ public static void main(String[] args) throws Exception{ //1、注册驱动,什么是驱动?能够让java连接数据库,也就是实现jdbc接口规范就是驱动 Class.forName("com.mysql.jdbc.Driver");//硬编码 /* -
MrFant revised this gist
Dec 4, 2018 . No changes.There are no files selected for viewing
-
MrFant revised this gist
Dec 4, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ public class jdbc{ public static void main(String[] args) throws exception{ //1、注册驱动,什么是驱动?能够让java连接数据库,也就是实现jdbc接口规范就是驱动 Class.forName("com.mysql.jdbc.Driver");//硬编码 /* * 2、通过驱动管理者获取数据库连接 -
MrFant revised this gist
Dec 4, 2018 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,6 @@ public class jdbc{ public static void main(String[] args) throws exception{ //1、注册驱动,什么是驱动?能够让java连接数据库,也就是实现jdbc接口规范就是驱动 Class.forName("com.mysql.jdbc.Driver");//硬编码 /* * 2、通过驱动管理者获取数据库连接 @@ -38,4 +35,6 @@ public static void main(String[] args) throws exception{ //6、关闭连接 rs.close(); ps.close(); conn.close(); } } -
MrFant revised this gist
Dec 4, 2018 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ public class jdbc{ public static void main(String[] args) throws exception{ } } //1、注册驱动,什么是驱动?能够让java连接数据库,也就是实现jdbc接口规范就是驱动 Class.forName("com.mysql.jdbc.Driver");//硬编码 -
MrFant revised this gist
Dec 4, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ public class jdbc{ public static void main() throws exception } //1、注册驱动,什么是驱动?能够让java连接数据库,也就是实现jdbc接口规范就是驱动 Class.forName("com.mysql.jdbc.Driver");//硬编码 -
MrFant revised this gist
Dec 4, 2018 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ public class jdbc{ public static void main() } //1、注册驱动,什么是驱动?能够让java连接数据库,也就是实现jdbc接口规范就是驱动 Class.forName("com.mysql.jdbc.Driver");//硬编码 /* -
MrFant revised this gist
Dec 4, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ public class jdbc //1、注册驱动,什么是驱动?能够让java连接数据库,也就是实现jdbc接口规范就是驱动 Class.forName("com.mysql.jdbc.Driver");//硬编码 /* -
MrFant revised this gist
Dec 4, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ public class j //1、注册驱动,什么是驱动?能够让java连接数据库,也就是实现jdbc接口规范就是驱动 Class.forName("com.mysql.jdbc.Driver");//硬编码 /* -
MrFant revised this gist
Dec 4, 2018 . No changes.There are no files selected for viewing
-
MrFant revised this gist
Dec 4, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ public //1、注册驱动,什么是驱动?能够让java连接数据库,也就是实现jdbc接口规范就是驱动 Class.forName("com.mysql.jdbc.Driver");//硬编码 /* -
MrFant revised this gist
Dec 4, 2018 . 1 changed file with 37 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,37 @@ //1、注册驱动,什么是驱动?能够让java连接数据库,也就是实现jdbc接口规范就是驱动 Class.forName("com.mysql.jdbc.Driver");//硬编码 /* * 2、通过驱动管理者获取数据库连接 * DriverManager是驱动实现类的管理者。 * url:连接数据库的位置,端口号,数据库名 * jdbc:mysql://localhost:3306/test_01 */ Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_1", "root", "root");//(硬编码) /* * 3、获得sql语句执行者 * statement:执行sql语句对象 * sql语句必须是完整的。 * preparedStatement:预处理(常用) * sql语句可以不是完整的,可以将参数用?替代,然后在预编译后加入未知参数 * */ //定义sql语句,?表示占位符 String sql = "select * from user where id = ?"; //硬编码 PreparedStatement ps = conn.prepareStatement(sql); ps.setInt(1, 1); //硬编码 //4、获取sql语句执行结果,resultset /* * executeQuery():查询操作 * executeUpdate():增删改操作 */ ResultSet rs= ps.executeQuery(); //5、处理结果 while(rs.next()){ System.out.println(rs.getInt(1));;//index代表第几列,从1开始 } //6、关闭连接 rs.close(); ps.close(); conn.close(); -
MrFant created this gist
Dec 4, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ _