I am facing weird issue in my grail project and after trying a lot i am posting this question here.I have tried all the URL related combination form http://jtds.sourceforge.net/faq.html#noSuitableDriver and other stack over flow answers like Help me create a jTDS connection string.
I am working on grails 2.4.3 project with groovy 2.3 and trying to connect with SQL Server database using jtds 1.3.1 but always getting "No suitable driver found for jdbc:jtds:sqlserver:" But to test this scenario i have written stand alone program as given below for same data base using same jar jtds 1.3.1 and its working fine.
try{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
String url = "jdbc:jtds:sqlserver://<hostname>:<port>/<database>";
Connection con = DriverManager.getConnection(url,"user","password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);}
Below I have provided the grails project code snippet for connection class
class SQLServerConnection implements DBConnection {
@Override
public Connection getConnection(String serverName, String databaseName) {
// TODO Auto-generated method stub
Class.forName("net.sourceforge.jtds.jdbc.Driver");
String url = "jdbc:jtds:sqlserver://<host>:<port>/<database>";
Connection con = DriverManager.getConnection(url,"user","password");
return con
}
Action form where i am calling this method
def dataFaucetColumn (){
def currentApp = RawDataApp.get(params.int('id'))
String query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='"+currentApp?.tableName +"'"
Connection con = new SQLServerConnection().getConnection(currentApp?.servers,currentApp?.databaseName)
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query); }
waiting for your answers.