javajavax。坚持不懈键入查询。getSingleResult()NoResultException,即使记录存在
javax。坚持不懈键入查询。getSingleResult()NoResultException,即使记录存在。下面的代码很好,记录率为99%,但结果为1%。DB是SQLServer2016。当我使用javax时,我有一个emplt列表。坚持不懈查询createNativeQuery和查询。getResultList()
public TApplicationDocument getDocumentById(int id) {
TypedQuery<TApplicationDocument> q = getEntityManager().createQuery(
"FROM TApplicationDocument where transientKey = :transientKey", TApplicationDocument.class);
q.setParameter("transientKey", id);
TApplicationDocument d=null;
try {
d = q.getSingleResult();
System.out.println("AppDocumentTitle "+d.getAppDocumentTitle());
} catch (NoResultException e) {
logger.debug("No result forund for... "+id);
System.out.println("No result forund for... "+id);
} catch (Exception e) {
logger.debug(" Tapp Dao IMple Exception for... "+id);
}
return d;
}
我可以采取什么不同的方法来获取此1%SQL server db的记录,或者如何进行调试。 一、 只是尝试通过简单的jdbc代码获取,但它并没有进入while循环,有些ID甚至记录存在于sqlserver2016中。建议我如何调试
public class JdbcSelectDemo {
public static void main(String[] args) { `
String dbURL = "XXXXXXXXXX";`
String username = "XXXXXXX"; String password = "XXXXXXXXX";
try (Connection conn = DriverManager.getConnection(dbURL, username, password)) {
String sql = "SELECT * FROM TApplicationDocument t where transientKey='115'";
System.out.println("Sql to be executed:"+sql);
Statement statement = conn.createStatement();
ResultSet result = statement.executeQuery(sql);
while (result.next()){
System.out.println("in side"+result.getString(1));
}
System.out.println("End...");
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
共 (0) 个答案