java中jdbc數據庫連接

package ch06.dao;

import java.sql.*;

public class baseDao {

public static final String  DRIVER="net.sourceforge.jtds.jdbc.Driver";
public static final String  URL="jdbc:jtds:sqlserver://localhost:1433/restrant";
public static final String  NAME="sa";
public static final String  PW="";

public static Connection con()
{
 Connection connection=null;
 try{
  Class.forName(DRIVER);
  connection=DriverManager.getConnection(URL,NAME,PW);
 }catch(Exception e)
 {
  e.printStackTrace();
 }
 return connection;
}
public static void closeAll(PreparedStatement pstmt,Connection con,ResultSet rs)
{

 try {
  if (pstmt!=null) {
  pstmt.close();
  }
  if (con!=null) {
   con.close();
   }
  if (rs!=null) {
   rs.close();
   }
 } catch (Exception e) {
  e.printStackTrace();
 }
 
}
}
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章