我正在尝试从select语句返回一个值.它只有一个值,因为我返回的值来自主键列.
SQL语句是 SELECT itemNo FROM item WHERE itemName = 'astringvalue';
我获取值的方法如下所示:
private String viewValue(Connection con, String command) throws SQLException
{
String value = null;
Statement stmt = null;
try
{
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(command);
while (rs.next())
value = rs.toString();
}
catch (SQLException e )
{
e.printStackTrace();
}
finally
{
if (stmt !=
null) { stmt.close(); }
}
return value;
}
Run Code Online (Sandbox Code Playgroud)
我也有一个getConnection()方法.
这是我用来调用viewValue方法的方法:
if((action.getSource() == btnSave) ||(action.getSource() == btnSavePrint) )
{
String findItemNoCommand = …Run Code Online (Sandbox Code Playgroud) 我尝试运行以下代码.它编译,但抛出ClassCastException.如果有人能帮助我找出原因,我会很高兴的.
double costprice = 0;
Object[] possibilities = null;
costprice = (double) JOptionPane.showInputDialog(
alphaPOS,
"Cost Price:",
"Enter Values",
JOptionPane.PLAIN_MESSAGE,
null,
possibilities,
"");
Run Code Online (Sandbox Code Playgroud)