求教啊 一个很费解的 java access 数据库问题啊 ……
在access 中 对 一个表的查询结果 保存后 可以直接对其再进行 select 查询 但是 我用java的时候 为什么 得不到结果程序代码:
这个是我测试用的代码
try{
String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\Users\\Administrator\\Desktop\\mess.mdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(url);
// System.out.println("数据库连接成功!!");
Statement sta = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String strHuancheng="select * from zhidaLine where a.Stop='"+tf1.getText()+"' and b.Stop='"+tf2.getText()+"' " ;
ta.setText("dian 1");
ResultSet res= sta.executeQuery(strHuancheng);
ta.setText("dian 2");
if(res.next())
{
ta.setText("dian 3");
//String strBegin = res.getString("a.Stop");
//String strEnd =res.getString("b.Stop");
String strRoute=res.getString(3);
int iStopCount = res.getInt("b.Position")-res.getInt("a.Position");
Integer Count =new Integer(iStopCount);
ta.setText("dian 4");
ta.setText("从 "+tf1.getText()+"到 "+tf2.getText()+" 存在直达线路,建议您乘坐"+strRoute+"车"
+"中间共经过"+Count.toString()+"个站点");
res.close();
sta.close();
conn.close();
}
}
catch(Exception x)
{
}
其中 dian1 dian2 dian3 dian4 是我测试用的 为的是判断 执行的哪里出问题了 可以看到的是 能够显示 dian3 也就是说明 if 内的条件判断是正确的 但是下面一开始获取数据库内容的时候 就没反映了 dian4 也输不出来……
try{
String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\Users\\Administrator\\Desktop\\mess.mdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(url);
// System.out.println("数据库连接成功!!");
Statement sta = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String strHuancheng="select * from zhidaLine where a.Stop='"+tf1.getText()+"' and b.Stop='"+tf2.getText()+"' " ;
ta.setText("dian 1");
ResultSet res= sta.executeQuery(strHuancheng);
ta.setText("dian 2");
if(res.next())
{
ta.setText("dian 3");
//String strBegin = res.getString("a.Stop");
//String strEnd =res.getString("b.Stop");
String strRoute=res.getString(3);
int iStopCount = res.getInt("b.Position")-res.getInt("a.Position");
Integer Count =new Integer(iStopCount);
ta.setText("dian 4");
ta.setText("从 "+tf1.getText()+"到 "+tf2.getText()+" 存在直达线路,建议您乘坐"+strRoute+"车"
+"中间共经过"+Count.toString()+"个站点");
res.close();
sta.close();
conn.close();
}
}
catch(Exception x)
{
}
其中 dian1 dian2 dian3 dian4 是我测试用的 为的是判断 执行的哪里出问题了 可以看到的是 能够显示 dian3 也就是说明 if 内的条件判断是正确的 但是下面一开始获取数据库内容的时候 就没反映了 dian4 也输不出来……
[ 本帖最后由 n272367953 于 2012-6-17 00:26 编辑 ]
----------------解决方案--------------------------------------------------------
没人解释么……
----------------解决方案--------------------------------------------------------
伤心啊 有人回答木有
----------------解决方案--------------------------------------------------------
难道都睡觉了?
----------------解决方案--------------------------------------------------------