有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

加密列的jdbc连接时出现java SQL异常

我在SQL中为otp表编写了SQL连接代码。我正在使用column encryption setting=启用查询结果,但eclipse中的同一查询给了我以下异常:

com.microsoft.sqlserver.jdbc.SQLServerException: The data types varchar(12) encrypted with (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'wc_local_machine_mv_column_key', column_encryption_key_database_name = 'Ilend_uat') collation_name = 'Latin1_General_BIN2' and varchar are incompatible in the equal to 
operator.
    at 

com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:262)
        at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1632)
        at com.mic

rosoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:872)
    

我的代码是:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class JavaConnect2SQL {

public static void main(String[] args) throws ClassNotFoundException, InterruptedException {

try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// TODO Auto-generated method stub
//String url="jdbc:sqlserver://LAPTOP-F0E1C4GT\\SQLEXPRESS;databaseName=BikeStores;";
//String user="sa";
//String password="NewPassword@123";


String url = "jdbc:sqlserver://52.172.161.203;user=username;password=userpass;databaseName=Ilend_uat;column encryption setting = enabled";
//connServer.connect(url);


Connection connection=DriverManager.getConnection(url);
System.out.println("Connected");
    Statement statement = connection.createStatement();

//*****
       
       
        System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.navigate().to("https://indialends.com/");
        driver.findElement(By.linkText("Personal Loan")).click();
 
    //driver.findElement(By.name("li_display_name")).getAttribute(rs.getString(1));
    
    
    driver.navigate().to("https://indialends.com/");
    driver.manage().window().maximize();
    String s = driver.getCurrentUrl();

    System.out.println(s);
    driver.getTitle();
    String x = driver.getTitle();
    System.out.println(x);

 driver.findElement(By.linkText("Personal Loan")).click();
    driver.findElement(By.id("li_display_name")).sendKeys("RAVNEET KAUR");
    driver.findElement(By.id("email")).sendKeys("ravneetkaur@indialends.com");
    driver.findElement(By.name("pincode")).sendKeys("122018");
    driver.findElement(By.id("employment")).click();
    Thread.sleep(5000);
    driver.findElement(By.id("salaried12")).click();
    Thread.sleep(5000);

    driver.findElement(By.id("companyName")).sendKeys("INDIALENDS");

    Thread.sleep(10000);
    driver.findElement(By.id("monthlyIncome")).sendKeys("34000");
    driver.findElement(By.id("mobile")).sendKeys("5589019322");
    driver.findElement(By.id("li_submit")).click();
    Thread.sleep(5000);

    WebDriverWait wait = new WebDriverWait(driver, 30);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.id("control-indicator"))).click();
    String s2 = driver.getCurrentUrl();
    WebDriverWait wait2 = new WebDriverWait(driver, 30);
    String query = "select top 1 * from mobileverification_encryption WHERE mobileno='5589019322' order by mvid desc";
    ResultSet rs = statement.executeQuery(query);
    while(rs.next()){
       System.out.println(rs.getString(1));
       Thread.sleep(2000);
    driver.findElement(By.id("txt_otp")).sendKeys(rs.getString(1));
    Thread.sleep(2000);
    driver.findElement(By.id("btn_mobile_verify")).click();
    System.out.println(s2);
    driver.getTitle();
    String x1 = driver.getTitle();
    System.out.println(x1);
    Thread.sleep(5000);
    
  
    
} }catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("Oops,there is error");
e.printStackTrace();



}
//driver.findElement(By.id("txt_otp")).sendKeys("55555");
}

}

我错过了什么

更新:我能够解决异常,但问题仍然是一样的,我试图从数据库获取的otp是加密的,我想将其转换为6位otp,并在otp弹出窗口上传递到前端。Eclipse正在像这样返回给我,请在此处输入图像描述

在db中,这很好,因为我们使用column encryption setting=enabled如何在JDBC中处理这个问题,同时建立连接如果在查询字符串中我再次通过“column encryption setting=enabled”,它会给出异常字符串url=“JDBC:sqlserver://104.211.116.31:2658;用户=用户名;密码=通过;databaseName=ilend_live;columnEncryptionSetting=Enabled“我正试图将此v_代码发布到前端,在此处输入图像描述 enter image description here

enter image description here


共 (0) 个答案