package test.jdbc;
import java.sql.*;
public class SqlServerJdbcTester {
public static void main(String args[]) throws SQLException, ClassNotFoundException {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String user = "testuser";
String password = "testpass";
String database = "ssdb";
/*
Connection conn = DriverManager.getConnection(
"jdbc:sqlserver://localhost:1433;databaseName=" + database
+ ";integratedSecurity=true");
*/
Connection conn = DriverManager.getConnection(
"jdbc:sqlserver://localhost:1433;databaseName=" + database
+ ";", user, password);
System.out.println("connected.");
DatabaseMetaData dbmd = conn.getMetaData();
System.out.println("positioned updates is supported? - " +
dbmd.supportsPositionedUpdate());
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("SELECT AREA_CODE, AREA_NAME FROM AREA");
while (rset.next()){
System.out.println(rset.getString(1) + "\t" + rset.getString(2));
}
System.out.println("Your JDBC installation is correct.");
rset.close();
stmt.close();
conn.close();
}
}
|