import java.sql.*;
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("Driver is loaded");
Connection c = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=***;user=***;password=***");
System.out.println("Connection created");
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select * from data");
System.out.println("ID\tName\tCity\tAge");
while(rs.next()) // Retrieve data from ResultSet
{
System.out.println(rs.getString(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3)+"\t"+rs.getString(4));
}
}
catch(Exception e)
{
System.out.println("Exception : " +e);
}
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("Driver is loaded");
Connection c = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=***;user=***;password=***");
System.out.println("Connection created");
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select * from data");
System.out.println("ID\tName\tCity\tAge");
while(rs.next()) // Retrieve data from ResultSet
{
System.out.println(rs.getString(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3)+"\t"+rs.getString(4));
}
}
catch(Exception e)
{
System.out.println("Exception : " +e);
}
No comments:
Post a Comment