sqlserver2008或sqlserver2005:
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbcUrl=jdbc:sqlserver://127.0.0.1:1433;DatebaseName=XX
user=XX
password=XX
sqlserver2000:
driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
jdbcUrl=jdbc:sqlserver://127.0.0.1:1433;DatebaseName=YYSK.NET
user=sapassword=123456
package jdbc;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public class JDBCTest {
public static void main(String[] args) throws SQLException, ClassNotFoundException, IOException {
JDBCTest jdbcTest = new JDBCTest();
System.out.println(jdbcTest.getConnection());
}
public Connection getConnection() throws SQLException, ClassNotFoundException, IOException {
Properties properties = new Properties();
InputStream in = this.getClass().getClassLoader().getResourceAsStream("jdbc.properties");
properties.load(in);
String jdbcUrl = properties.getProperty("jdbcUrl");
String driver = properties.getProperty("driver");
String user = properties.getProperty("user");
String password = properties.getProperty("password");
Class.forName(driver);
return DriverManager.getConnection(jdbcUrl, user, password);
}
}