【发布时间】:2015-04-18 19:24:14
【问题描述】:
请告诉我如何解决代码中的错误。我想从 ms 访问表中获取详细信息。我使用数据和描述作为列。 date 是 ms 访问中的主键。所以请让我帮我从 ms 访问表中读取数据。
try{
connect();
stmt = (Statement) conn.createStatement();
String sql, ks = " ";
ks = JOptionPane.showInputDialog("enter the date of which you want to read");
String jk = " where date=" + ks;
sql = "SELECT [date],[description] FROM Table2" + jk;
System.out.println("1");
rs = ((java.sql.Statement) stmt).executeQuery(sql);
if(rs.next())
{
String date1="hello",description1="hii";
date1 = rs.getString("date");
description1=rs.getString("description");
JOptionPane.showMessageDialog(null,"Date:"+date1+"\n"+description1);
}
else
{
JOptionPane.showMessageDialog(null,"Sorry the record does not exist");
try
{
close();
}
catch(Exception ea)
{
JOptionPane.showMessageDialog(null, "Error:"+ea.getMessage());
}
}
}
catch(Exception ew)
{
JOptionPane.showMessageDialog(null, "Unable to fetch Data");
JOptionPane.showMessageDialog(null,""+ew.getMessage());
System.out.println(""+ew);
}
谢谢
【问题讨论】:
-
修正你的格式,我会告诉你错误的原因! ;)
-
我猜它的格式看起来不错。
-
不客气。格式化是一个常见的错误:)
-
@KarrthikReddyChinasani 您的错误与 java 无关。 SQL 查询的 where 子句中存在语法错误。请参阅 stackoverflow.com/questions/11814853/… 或 techrepublic.com/article/… 了解如何在 MS Access 中使用日期。
-
我使用字符串作为日期。我的意思是字符串已用于存储数据,例如 19apr2015。我在访问表中使用了长文本作为日期