當我運行硒網絡驅動程序本次測試情況下,我得到了下面的錯誤:發現JDBC沒有合適的驅動程序瘦:
值java.sql.SQLException:神諭:找到了JDBC沒有合適的驅動程序薄:@ 10.96.0.65:1521:orcl at java.sql.DriverManager.getConnection(DriverManager.java:602) at java.sql.DriverManager.getConnection(DriverManager.java:185) at Database.DatabaseValidation.test(DatabaseValidation的.java:50) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本機方法) 在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 在sun.reflect.DelegatingMethodAccessorImpl.invo ke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:47) at org .junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements .InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters .java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRu nner.runChild(BlockJUnit4ClassRunner.java:70) 在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:238) 在組織.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access $ 000(ParentRunner.java :53) at org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal。 junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
package Database;
import oracle.jdbc.*;
import static org.junit.Assert.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import oracle.jdbc.driver.*;
import java.sql.PreparedStatement;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
public class DatabaseValidation {
private WebDriver driver = null;
private Connection con = null;
private Statement stmt = null;
String baseUrl;
@Before
public void setUp() throws Exception {
// use firefox browser
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("SOFAdmin");
driver = new FirefoxDriver(myprofile);
baseUrl = "https://10.96.0.65:9443";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void test() throws SQLException, ClassNotFoundException {
// Load Microsoft SQL Server JDBC driver.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// Prepare connection url.
String url = "jdbc:oracle:thin:@10.96.0.65:1521:orcl";
// Get connection to DB.
con = DriverManager.getConnection(url, "POS_SOF", "POS_SOF");
// Create statement object which would be used in writing DDL and DML
// SQL statement.
stmt = con.createStatement();
// Send SQL SELECT statements to the database via the
// Statement.executeQuery
// method which returns the requested information as rows of data in a
// ResultSet object.
// define query to read data
try {
String query = "select * from ACCOUNTS";
ResultSet result = stmt.executeQuery(query);
if (result.next()) {
while (result.next()) {
// Fetch value of "username" and "password" from "result"
// object; this will return 2 existing users in the DB.
String username = result.getString("ID");
String password = result.getString("CODE");
// print them on the console
System.out.println("ID :" + username);
System.out.println("CODE: " + password);
}
result.close();
}
}
catch (SQLException ex) {
System.out.println(ex);
}
// Add a new user on the UI
String newtestusername = "test1234";
String newtestuserpassword = "1234";
// navigate to the site
driver.get(baseUrl + "/POSAdminTool/AdminToo"
+ "l/Login.faces");
// set new user name "NewTestUser"
driver.findElement(By.id("userID")).sendKeys(newtestusername);
// set new user password for the new user "NewTestUser"
driver.findElement(By.id("password")).sendKeys(newtestuserpassword);
// click on Add User button
driver.findElement(By.id("form1:btn_login")).click();
// verify the welcome message displayed
System.out
.println("Is welcome message displayed: "
+ isElementPresent(By
.xpath("//*[contains(.,'Welcome back ')]")));
// verify the new user in the database
// create a query
String newuserquery = "SELECT * From userlogin where username=?";
// create a statement
PreparedStatement stat = con.prepareStatement(newuserquery);
stat.setString(1, newtestusername);
try {
boolean hasResultSet = stat.execute();
if (hasResultSet) {
ResultSet result = stat.getResultSet();
// get new user name from the table
String newusername = result.getString("username");
// assert that new user name should be
assertEquals(newtestusername, newusername);
}
} catch (SQLException ex)
{
System.out.println(ex);
} finally {
con.close();
}
}
@After
public void tearDown() throws Exception {
// close the driver
driver.close();
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
}
親愛的duffymo,謝謝你的回覆,我只是想幫助朋友工作,因爲它不是我的專業。再次感謝您的幫助,我將嘗試尋找解決此錯誤的另一種方法。 –
不是另一種方式;就是這樣。如果這不是你的專業化,我會建議你的朋友找一個知道Java的人。 – duffymo
非常感謝您的評論 –