package apptest;
import java.sql.*;
public class AppTest {
public static void main(String[] args) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost:1433;"
+ "databaseName=Northwind;user=sa;password=;";
Connection con = DriverManager.getConnection(connectionUrl);
Statement stmt = null;
ResultSet rs = null;
String SQL = "SELECT * FROM Products";
stmt = con.createStatement();
System.out.println("Connection is created...");
rs = stmt.executeQuery(SQL);
while (rs.next()) {
System.out.println(rs.getString("ProductName") + " : " + rs.getString("UnitPrice"));
System.out.println(" done");
}
con.close();
System.out.println("Connection is closed...");
} catch (SQLException e) {
System.out.println("SQL Exception: " + e.toString());
} catch (ClassNotFoundException cE) {
System.out.println("Class Not Found Exception: " + cE.toString());
}
}
}