Friday, 20 January 2012

Integrating Microsoft JDBC Driver, MSSQL Server 2008 and Eclipse on Windows XP/7


Install and configure the JDBC Driver


Download Microsoft JDBC Driver for SQL Server from here (I used V2.0 in XP and V3.0 in win7)
Unpack the driver to c:\Program Files\ Microsoft SQL Server JDBC Driver 2.0 (or 3.0 depending on your version)
Add the driver path to Windows PATH this procedure is the same in XP and in Win7, do this “rightclick” on “My Computer” and select “Properties” this opens the “System Properties” window and select the “Advanced” tab




Click on “Environment Variables” (bottom of the window)



Select the “PATH” variable and add this to the end of the line “;c:\Program Files\ Microsoft SQL Server JDBC Driver 2.0\sqljdbc_2.0\enu\sqljdbc.jar” without the quotation marks but with the semicolon at the beguinnig, once again if you use V3.0 be sure to replace it accordingly.


Configure MS SQL Server 2008


Have an instance of MSSQL Server 2008 up and running (if you don’t know how read this), next, make sure your SQL Server as TCP-IP turned on, to do this go to the “SQL Server Configuration Manager”



Expand “SQL Server Network Configuration” and click on “Protocols for MSSQLSERVER” then on the right panel rightclick on TCP-IP and then “Enable”, this will allow for eclipse to access your SQL server through the MS SQL Driver.



After this you need to restart your SQL Server service like so:



Now it’s time to configure the user login that will be used to access the database, i created a test user for this (if you don’t know how to create a user go here), to configure a login expand your server instance, then “Security” and then “Logins”, locate your user login rightclick it and select “Properties”



On the “Login Properties” window (on the upper left corner) select “User Mapping” then choose which Databases your user will need to have access to (mine was SI_TP1) then select the “Database role membership” and be sure to select “db_datareader” and “db_datawriter”.



Use Eclipse to access your Database


Create a project and a class file that will be used to access your DB (if you don’t know how go here), next rightclick on your project in the “Package Explorer” go to “Build Path” and chose “Add Libraries”



In the “Add Library” window select “User Library” and click next



Next select “User Libraries…”



Click on “New…”



Give your Library a name like “MS_JDBC_2”



Then click on “ADD JARs..”



Navigate to your “c:\Program Files\ Microsoft SQL Server JDBC Driver 2.0\sqljdbc_2.0\enu\” folder and chose sqljdbc.jar file if your using XP or sqljdbc4.jar if your using Win7.
Click OK and return to Eclipse.


To access your database from eclipse use the following code:
SERVER_NAME = your server name
DB_NAME = the database you want do access
LOGIN = the login of your user
*** = that user password
SOME_TABLE = name of table in database
SOME_METHOD = ResultSet methods



import java.sql.*;
public class JDBCTest
{
public static void main(String[] args)
{
try
{
//Register JDBC driver
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionURL = "jdbc:sqlserver://SERVER_NAME;" +
"databaseName=DB_NAME;user=LOGIN;password=***;";
Connection con = DriverManager.getConnection(connectionURL);

//ENTER SQL STATMENTS HERE
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM SOME_TABLE");

while(rs.next())
{
System.out.print(rs.SOME_METHOD);
}

con.close();
}
catch(SQLException se)
{ System.out.println(se.getMessage()+"**"+se.getSQLState()+"**"+se.getErrorCode());
}

catch(Exception e)
{
e.printStackTrace();
}
}
}

If there is anything you found unclear or if you found an error please leave a comment.

Thursday, 5 January 2012

2012 – The year HTML5 wins

The fifth version of HTML gained much notoriety during 2011 by transforming the application development paradigm. HTML5 took the world by storm with the premise of being multi-platform, and giants like Microsoft, Google or Apple have its back.

Mobile devices are here to stay, every day more and more people buy them, and demand more and better apps and functionalities, hopping to be the next to come out with the next big, thing each manufacturer has created its own technological mushroom, this caused serious problems to content developers, because an app developed to run on iPhone doesn’t run on Android or Windows Phone and vice versa, but in the course of 2011 some big players changed their minds and now the path seems brighter, Apple banned Flash from their mobile devices and states that HTML5 is the future(1), Microsoft is revolutionizing its core, no more Win32 API, from now on its WinRT (Windows RunTime(2)) API and it has HTML5 and JavaScript in mind, another big step towards HTML5 was Microsoft dropping out of SilverLight, this is clearly a bet to try and catch the mobile train and it shows with Windows Mobile 7 and Metro style apps, Adobe as also recently stated that its dropping the ball on Flash(3).

HTML5 promises standardization and flexibility, it’s this ability to run on several platforms that is going to boost the standard.


Several companies are already making available some amazing content developed in HTML5, like Rovio who released AngryBirds for Chrome, or SuperGiants who released Bastion also available on Chrome Store.




1. http://www.apple.com/html5/
2. http://msdn.microsoft.com/en-us/library/windows/apps/hh464942.aspx
3. http://news.yahoo.com/adobe-drops-flash-mobile-devices-193154292.html