Make use of jtds-1.2.5.jar you can achive it.You may know how to include jar in your project (copy jar into lib folder of your project->rightclick->properties->java build path ->libraries ->navigate to where you have copied say lib folder select jar and hit ok).Write single ton class and make instance of this class and access where ever you need in your application.
public final class Database
{
public Connection connectionObj;
private Statement statement;
public static Database dataBase;
ResultSet res ;
Database()
{
String url = "jdbc:jtds:sqlserver://local address or server IP address;"+"databaseName=*****;encrypt=false;";
String driver = "net.sourceforge.jtds.jdbc.Driver";
String userName = "****";
String password = "*****";
try
{
Class.forName(driver).newInstance();
this.connectionObj = (Connection)DriverManager.getConnection(url,userName,password);
}
catch (Exception sqle)
{
sqle.printStackTrace();
}
}
public static synchronized Database getDbCon()
{
if ( dataBase == null )
{
dataBase = new Database();
}
return dataBase;
}
public ResultSet query(String query) throws SQLException
{
statement = dataBase.connectionObj.createStatement();
res = statement.executeQuery(query);
return res;
}
public int insert(String insertQuery) throws SQLException
{
statement = dataBase.connectionObj.createStatement();
int result = statement.executeUpdate(insertQuery);
return result;
}
}
How to use this class?
Database database = new Database();
Database.getDbCon();
try {
database.insert("Insert into tablename(coloum name) values (pass values);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}