java 怎么实现统一身份认证

发布网友 发布时间:2022-04-20 13:53

我来回答

1个回答

热心网友 时间:2023-07-15 05:03

package com.icss.carmall.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtil {

/**
* 获得数据库连接
* @return
*/
public static Connection getConn(){
Connection conn = null;

try {
// 加载驱动
Class.forName("net.sourceforge.jtds.jdbc.Driver");

final String url = "jdbc:jtds:sqlserver://127.0.0.1:1433/CarDB";

final String user = "sa";

final String password ="123456";

// 获得数据库连接
conn = DriverManager.getConnection(url, user, password);

} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return conn;
}

/**
* 关闭数据连接
* @param conn
* @param pstmt
* @param rs
*/
public static void closeConn(Connection conn, PreparedStatement pstmt, ResultSet rs){

if(null != conn){
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

if(null != pstmt){
try {
pstmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

if(null != rs){
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

public static void main(String[] args) {
DBUtil.getConn();
}

}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
15.235881s