任何解决以下问题的建议将不胜感激。
我正在尝试使用 java 运行 sql 语句,其中我一直有动态文件名例如这次我的完整文件名是"WTX-5010_HP_KYCMS18837P51144.txt"
这是我的 sql 语句:`SELECT processid, * FROM [Config].[AD].[FILELOG] where filename='WTX-5010_HP_KYCMS18837P51144.txt'
以下是我的脚本:
static String NewFileNmae = WTX-5010_HP_KYCMS18837P51144.txt;
System.out.println("Full New File Name is " + NewFileNmae);
try {
String strpQuery2 = "SELECT processid, * FROM [Config].[AD].[FILELOG] where filename=";
String connectionUrl = "jdbc:sqlserver://"+strpServer+":"+strpPort+";databaseName="+strpDatabase+";IntegratedSecurity=true";
// Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
String SQLS = strpQuery2+NewFileNmae;
System.out.println("SQLQuery is " + SQLS);
stmt = con.createStatement();
rs = stmt.executeQuery(SQLS);
while (rs.next()) {
ProcessID = rs.getString(1);
System.out.println("List value are " +ProcessID);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
在调试窗口中,我可以看到"SELECT processid, * FROM [Config].[AD].[FILELOG] where filename=WTX-5010_HP_KYCMS18837P51144.txt"上面脚本中打印的 sql 语句rs = stmt.executeQuery(SQLS);
我将文件名添加为变量,当自动生成动态文件名时,它不会将引号''与文件名一起添加。我怎么能在这里提到 NewFileName 变量的单引号?- 字符串 SQLS = strpQuery2+NewFileNmae;
波斯汪
相关分类