到目前为止,我一直在搜索网络,声明总是有if和else条件如a ? b : c.我想知道是否if可以不使用三元语句else.假设我有以下代码,我希望关闭PreparedStatement它,如果它不是null
(我使用的是Java编程语言.)
PreparedStatement pstmt;
//....
(pstmt!=null) ? pstmt.close : <do nothing>;
Run Code Online (Sandbox Code Playgroud) 我有TestingID变量,在我的Java代码SQL字符串如下.稍后将使用sql字符串prepareStatement.
int TestingID;
String sqlInsert = "INSERT INTO TESTING VALUES(TESTING_SEQ.NEXTVAL, ?, ?)";
...
MethodA(TestingID); //passing TestingID to MethodA
Run Code Online (Sandbox Code Playgroud)
我需要将新插入的记录的下一个序列值放入其中,TestingID以便我可以在另一个方法中使用它,如上所示.
我有许多不同内容的函数,但参数和try catch内部几乎相似.无论如何都要将函数包起来以减少冗余代码.
ResponseStatus GetPotatoList(GetPotatosRequest requestParam, out GetPotatosResponse response, out ResponseErrorType errorType)
{
ResponseStatus status = ResponseStatus.Fail;
response = new GetPotatosResponse();
//To Do
try
{
//To Do
status = ResponseStatus.Success;
}
catch(CustomException ex)
{
errorType = ResponseErrorType.CustomError;
}
catch(TimeoutException ex)
{
errorType = ResponseErrorType.Timeout;
}
catch(Exception ex)
{
errorType = ResponseErrorType.GeneralFailure;
}
return status;
}
Run Code Online (Sandbox Code Playgroud) 我有这3个实体的学生,工作人员和讨论.
他们的关系是这样的:1个学生可以发表很多讨论; 1名工作人员可以发表许多讨论 但是1次讨论只能由学生或工作人员发布.是否可以让外键studentID和staffID都驻留在讨论实体中?但这样做可能会使其中的每条记录在这两个属性中都有1个空值.
我有一张桌子如下:
产品(P_CODE,DESCRIPTION,PRODUCTION_DATE)
过期的产品是生产超过1年的产品.如何列出已过期的所有产品及其到期日期?
如何从字符串中提取部分,并在字符之间分隔" - "?例如,我想从"123-4567-9012"中提取"123"或从"123-4567-9012"中提取"4567",或者从相同的字符串中提取9012
在我的 MVC 视图中,我在表中显示来自我的模型的数据列表,如下所示。当一个字段满足我的 if-else 语句中的某些条件时,如何使指定的行改变颜色?似乎我不能为此在 if-else 中添加 jquery ......
我的看法:
...
<table>
...
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.field1)
</td>
<td>
@Html.DisplayFor(modelItem => item.field2)
</td>
<td>
@if(item.field3== 0){
//change this row to grey color
}
else {
@Html.DisplayFor(modelItem => item.field3)
}
</td>
....
</table>
Run Code Online (Sandbox Code Playgroud) c# ×2
if-statement ×2
java ×2
oracle ×2
sql ×2
asp.net-mvc ×1
erd ×1
html-table ×1
methods ×1
select ×1
sequence ×1
uml ×1
wrapper ×1