java中jdbc数据库连接

    技术2022-06-27  129

    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(); } }} 


    最新回复(0)