I am trying to connect to my SQL Server 2008 database from Java and I\'m having the same problem from this thread.
String userName = \"xxxx\";
String password =
public static final String URL = "jdbc:sqlserver://localhost:1433;databaseName=dbName";
public static final String USERNAME = "xxxx";
public static final String PASSWORD = "xxxx";
/**
* This method
@param args command line argument
*/
public static void main(String[] args)
{
try
{
Connection connection;
DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
connection = DriverManager.getConnection(MainDriver.URL,MainDriver.USERNAME,
MainDriver.PASSWORD);
String query ="select * from employee";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
while(resultSet.next())
{
System.out.print("First Name: " + resultSet.getString("first_name"));
System.out.println(" Last Name: " + resultSet.getString("last_name"));
}
}catch(Exception ex)
{
ex.printStackTrace();
}
}