zoukankan      html  css  js  c++  java
  • 01、JDBC连接

    ① 下载JDBC-MySQL数据库驱动

    链接:https://pan.baidu.com/s/1KtSZZ5hXlxu2QrmsXg3lkA
    提取码:1pbl

    ② 加载JDBC-MySQL数据库驱动

    范例:MySQL数据库驱动加载

    Class.forNmae("com.mysql.jdbc.Driver");

    注:上面语句需要try catch捕获 或者throws异常

    ③ 连接数据库

       java.sql包中的DriverManager类有两个忠于建立连接的类方法(static方法)

    NO.

    方法名称

    类型

    描述

    01

    public static Connection getConnection(String url,Properties info)throws SQLException

    普通

    建立到给定数据库 URL 的连接

    02

    public static Connection getConnection(String url,String user,String password)throws SQLException

    普通

    建立到给定数据库 URL 的连接

    范例:连接数据库

    package com.hsp;

    import java.sql.Connection;

    import java.sql.DriverManager;

    public class testDatabase {

    /**

    * @param args

    */

    public static void main(String[] args) {

    // TODO Auto-generated method stub

    Connection con = null;

    String DBname = "jdb"; //数据库名字

    //  String url = "jdbc:mysql://localhost:3306/"+DBname+"?useSSL=true";

    //如果数据库的表中的记录有汉字,那么需要characterEnconding=gb2312 或utf-8 如果不清楚有没有函数推荐使用下列这个方法

    String url = "jdbc:mysql://localhost:3306/"+DBname+"?useSSL=true&characterEncoding=utf-8";

    String username = "root";//数据库账号

    String password = "root";//数据库密码

    try {

    Class.forName("com.mysql.jdbc.Driver");

    con = DriverManager.getConnection(url, username, password);//连接代码

    System.out.println("输出con地址:"+con);

    } catch (Exception e) {

    // TODO: handle exception

    System.out.println(e);

    }

    }

    }

  • 相关阅读:
    TensorFlow------学习篇
    汉语分词工具的研发-----
    SVM强化学习
    RNN和LSTM系统强化学习———
    CRF学习笔记
    Word2vector---------学习笔记
    FindAllAnagramsinaString
    Java中比较两个字符串是否相等的问题
    15003_特殊数字
    雷林鹏分享:Lua break 语句
  • 原文地址:https://www.cnblogs.com/HOsystem/p/11638641.html
Copyright © 2011-2022 走看看