赞
踩
- #autoReconnect 当数据库连接丢失时是否自动连接,取值true/false false
- #maxReconnects 如果autoReconnect为true,此参数为重试次数,缺省为3次 3
- #initialTimeout 如果autoReconnect为true,此参数为重新连接前等待的秒数 2
- #maxRows 设置查询时返回的行数,0表示全部 0
- #useUnicode 是否使用unicode输出,true/falsefalse
- #characterEncoding 如果useUnicode,该参数制定encoding类型,建议使用utf8 无
- #createDatabaseIfNotExist 当JDBC连接指定数据库,如果此数据库不存在,此参数值为true时,则自动创建此数据库
- jdbc:mysql://localhost:3306/hello_mysql?
- createDatabaseIfNotExist=true&
- amp;useUnicode=true&
- amp;characterEncoding=utf8&
- amp;autoReconnect=true&
- amp;useLocalSessionState=true
- public static Connection getConn(String username,String password,String DBname){
- String driver="com.mysql.jdbc.Driver";
- String url="jdbc:mysql://localhost:3306/"+DBname;
- Connection conn=null;
- try {
- Class.forName(driver);
- conn=DriverManager.getConnection(url,username,password);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return conn;
- }
- public static void main(String[] args) throws SQLException {
- Connection conn=getConn("root", "", ""); //没有密码就什么都不写,空字符串
- Statement stmt=conn.createStatement();
- ResultSet rs=stmt.executeQuery("show databases");//执行查询
- while(rs.next()){//遍历查询结果
- System.out.println(rs.getString(1));
- }
- stmt.close();//显示关闭Statement对象,释放资源
- conn.close();
- //关闭数据库连接,这是个好习惯。尽管在程序运行结束会自动关闭。但web应用是不会结束运行的。
- }
—————————————————————————————————————————————————*
下载地址:
https://item.taobao.com/item.htm?id=555888526201
01.高级架构师四十二个阶段高
02.Java高级系统培训架构课程148课时
03.Java高级互联网架构师课程
04.Java互联网架构Netty、Nio、Mina等-视频教程
05.Java高级架构设计2016整理-视频教程
06.架构师基础、高级片
07.Java架构师必修linux运维系列课程
08.Java高级系统培训架构课程116课时
+
hadoop系列教程,java设计模式与数据结构, Spring Cloud微服务, SpringBoot入门
—————————————————————————————————————————————————–
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。