资源简介
http://blog.csdn.net/deathislikethewind/article/details/71122647
代码片段和文件信息
package stu;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class ConnectMysql{
private static final String url = “jdbc:mysql://127.0.0.1:3306/sql?useUnicode=true&characterEncoding=utf-8&useSSL=false“;
//MySQL 表示连接的数据库 是 MySQL ; 127.0.0.1表示你的MySQL的远程端地址(127.0.0.1表示的是本地地址) 3306表示是这个端口
//后边的一大串?useUnicode=true&characterEncoding=utf-8&useSSL=false 设置数据库属性如果不添加被曝↓↓↓↓
//WARN:Establishing SSL connection without server‘s identity verification is not recommended.KILL WARN ?useUnicode=true&characterEncoding=utf-8&useSSL=false ↑
private static final String name = “com.mysql.jdbc.Driver“;
public static final String user = “root“; //数据库的用户名
public static final String password = “ABCabc123“; //数据库的用户密码
public Connection connect = null; //连接类这就是那个链接啊
public PreparedStatement pStatement = null; //准备声明
public ConnectMysql(String SqlStatement){
try{
Class.forName(name); //指定连接类型
connect = DriverManager.getConnection(url user password); //获取连接
pStatement = connect.prepareStatement(SqlStatement); //准备执行语句
}
catch (Exception e) {
e.printStackTrace();
}
}
public void close() {
try {
this.connect.close(); //关闭链接
this.pStatement.close(); //关闭准备语句
} catch (SQLException e) {
e.printStackTrace();
}
}
}
评论
共有 条评论