Selenium中的数据库连接错误

时间:2017-01-29 13:29:48

标签: mysql

我写了一个从数据库中获取数据的类:

@Test
    void ts() throws ClassNotFoundException, SQLException{
    Class.forName("com.mysql.jdbc.Driver");

    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/selenium","root","root");

    Statement stm=con.createStatement();

    ResultSet rs=stm.executeQuery("select * from seleniumusers");

    while(rs.next()){

         name=rs.getString("firstname");
        System.out.println(name);
        e(mysql)

但是一旦浏览器打开,从testng运行测试就会给出错误:

Warning: mysql_pconnect() [function.mysql-pconnect]: Can't connect to MySQL server on 'localhost' (10061) in C:\Program Files\vtigercrm-5.2.1\apache\htdocs\vtigerCRM\adodb\drivers\adodb-mysql.inc.php on line 373

1 个答案:

答案 0 :(得分:-1)

public WebDriverWait wait;
    String filename;
    File file;
    Workbook RegExcel = null;
    Row row = null;
    Sheet RegExcelSheet = null;
    FileInputStream inputStream;
    public String[][] excelDataValue;
    public int rowCount;
    public List<WebElement> AllRegularization=null;;
    
        String projectPath = System.getProperty("user.dir");

       
        @Given("^User Save Excel At Said Location$")
        public void user_save_excel_at_said_location() throws Throwable {
            filename="RegDates.xlsx";
            file = new File (projectPath +"\\"+ filename);      
        }

        @When("^Excel File Is Readable$")
        public void excel_file_is_readable() throws Throwable {
            inputStream = new FileInputStream(file);        
                
            String fileExtensionName = filename.substring(filename.indexOf("."));
        }

        @Then("^Read The Excel$")
        public void read_the_excel() throws Throwable {
            RegExcel = new XSSFWorkbook(inputStream);        
            RegExcelSheet = RegExcel.getSheet("Sheet1");
        }

        @And("^Create Array For Dates Data In Excel$")
        public void create_array_for_dates_data_in_excel() throws Throwable {
            rowCount = RegExcelSheet.getLastRowNum()-RegExcelSheet.getFirstRowNum();
            excelDataValue = new String[rowCount+1][5];
        
            for (int i = 0; i < rowCount+1; i++) 
            {
        
                row = RegExcelSheet.getRow(i);  
                for (int j = 0; j < row.getLastCellNum(); j++) 
                {
                    excelDataValue[i][j]=row.getCell(j).toString();
                    //System.out.println(row.getCell(j).toString());
                 }  
            }   
            
            
            
        }