Java 行集/数据访问对象失败

发布于 2024-11-27 14:39:36 字数 1616 浏览 0 评论 0原文

我使用行集在我的 selenium 框架中传递查询结果。有时,数据访问对象会抛出以下

java.sql.SQLException:没有找到适合 jdbc:jtds:sqlserver://MYDatabasename:1433/DB 的驱动程序

它使用相同的驱动程序和行集来访问并且仅偶尔会失败。任何帮助将不胜感激。

RowSet:

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

    CachedRowSet rs;
    String ROWSET_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();

代码示例:

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();

使用并依次调用行集:

  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;

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 ROWSET_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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏爱你一生 2024-12-04 14:39:36

这似乎是不可能的。驱动程序类要么已加载,要么未加载。加载后,使用相同的 JDBC URL 连续调用 DriverManager.getConnection() 永远不会出现该错误。还有什么事情发生吗?

编辑:我看到的唯一有问题的事情是您的所有 Configuration.* 属性似乎都是某个类中的字段。如果其中一些属性在测试之间更改值,则可能是您的 JDBC 驱动程序由于错误的属性值而引发异常,例如 Configuration.DBConfiguration.DBConnString.如果它相当可重复,请尝试更改

rs.setUrl(Configuration.DBConnString + DB);

为“

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

当异常发生时,查看字符串是否看起来不同”。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文