package com.pub; import java.sql.Connection; import java.sql.DriverManager; public class DBConnection { public static Connection getConnction(){ Connection con=null; try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:driver={sql server}; server=.; database=myDatabaseName;user=;pwd=;"); }catch(Exception e){ System.out.println(e.getMessage()); } return con; } public void main(String args[]){ Connection con=DBConnection.getConnction(); if(con!=null){ System.out.println("Connection is successful!!"); }else{ System.out.println("Connection is fail!!"); } } }
java连接数据库不用加载驱动_java不用驱动连接MSSQL数据库
最新推荐文章于 2021-07-15 09:15:21 发布