开发者

Java Row Set / Data Access Object Failure

I use a Row Set to pass query results in my selenium framework. Occasionally the data access object throws the following

java.sql.SQLException: No suitable driver found for jdbc:jtds:sqlserver://MYDatabasename:1433/DB

It uses this same driver and rowset to access and only fails occasionally. Any help would be appreciated.

RowSet:

public static RowSet GetRowSet(String SqlQuery, String[] Parameters, String DB){

    CachedRowSet rs;
    String R开发者_开发技巧OWSET_IMPL_CLASS = "com.sun.rowset.CachedRowSetImpl";
    rs = null;

    try {
        Class<?> c = Class.forName(ROWSET_IMPL_CLASS);
        rs = (CachedRowSet) c.newInstance();

        rs.setUrl(Configuration.DBConnString + DB);
        rs.setUsername(Configuration.DBUser );
        rs.setPassword(Configuration.DBPwd );
        rs.setReadOnly(true);
        rs.setCommand(SqlQuery);

        for (int    p=0; 
                    p<Parameters.length; 
                    p++)

        { 
            rs.setString(p+1, Parameters[p]);   
        }

        rs.execute();

Example of code:

public void examplevoid(String string, String string2)

throws Exception {

    RowSet RoS = null;  
    RoS = Example.GetExample(string, string2);
    while (RoS.next()) {
        String Example = RoS.getString("Example");
        selenium.click(Example)
        selenium.waitForPageToLoad(setup.timeoutsetting);
    }
    RoS.close();

Which uses and in turn calls the rowset:

  public static RowSet GetExample(String string, String string2) throws 
  String[] Parameters = {string, string2};
  RowSet ExampleRowSet= null;
  ExampleRowSet = DataAccess.GetRowSet("Some SQL HERE", Parameters,  Configuration.DB); 

return Example;


That seems impossible. Either the driver class is loaded, or it isn't. Once loaded, successive calls to DriverManager.getConnection() with the same JDBC URL should never give that error. What else is going on?

Edit: The only questionable thing I see is that all of your Configuration.* properties appear to be fields in a class somewhere. If some of those properties are changing values between tests, maybe your JDBC driver is causing that exception to be thrown because of a bad property value, like the Configuration.DB or Configuration.DBConnString. If it's fairly repeatable, try changing

rs.setUrl(Configuration.DBConnString + DB);

to

String url = Configuration.DBConnString + DB;
log.debug("Using JDBC URL: " + url);
rs.setUrl(url);

When the exception happens, see if the string looks different.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜