String str = "";
conn = DBHelper.getConn();
try
{
ps = conn.prepareStatement("select (select b.Name from Permission b where b.ID=a.PermissionID) name from UserAccountXPermission a where a.UserAccountID = (select ID from UserAccount where UserName=?)");
ps.setString(1, ua.getUsername());
rs = ps.executeQuery();
str = rs.getString("name");
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
DBHelper.close(conn, ps, rs);
}
return str;为什么执行这条语句会报错 不能执行这么长的吗?还是其他方法

解决方案 »

  1.   

    select (select b.Name from Permission b where b.ID=a.PermissionID) name from UserAccountXPermission a where a.UserAccountID = (select ID from UserAccount where UserName=?)这句sql错了
    换成
    select name from UserAccountXPermission a where a.UserAccountID = (select ID from UserAccount where UserName=?)
    试试
      

  2.   

    我的UserAccountXPermission 没有name的啊~只有UserAccountID和PermissionID ,Permisson表里才有name  我在数据库里运行可以的。但是程序就报错
      

  3.   

    java.sql.SQLException: Before start of result set
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
    at com.mysql.jdbc.ResultSet.checkRowPos(ResultSet.java:720)
    at com.mysql.jdbc.ResultSet.getStringInternal(ResultSet.java:5624)
    at com.mysql.jdbc.ResultSet.getString(ResultSet.java:5544)
    at com.mysql.jdbc.ResultSet.getString(ResultSet.java:5584)
    at Handler.UserAccountHandler.checkUser(UserAccountHandler.java:48)
    at UI.LoginUI$Monitor.actionPerformed(LoginUI.java:72)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
      

  4.   

    select (select   这里明显语法错误!
      

  5.   

    rs = ps.executeQuery();
    while(rs.next()){
    str = rs.getString("name");
    }跟sql没关系么,虽然sql写法有点
                
      

  6.   

    不知道怎么写好点。。能指教下吗什么意思?
    结果集一行的话,
    直接
    rs = ps.executeQuery();
    rs.next();//加上这一句
    str = rs.getString("name");多行就像上面一样,用while
      

  7.   

    不知道怎么写好点。。能指教下吗什么意思?
    结果集一行的话,
    直接
    rs = ps.executeQuery();
    rs.next();//加上这一句
    str = rs.getString("name");多行就像上面一样,用while
    我指的是那个sql语句啊~
      

  8.   

    sql语句的问题,你最后是得到哪张表中的name ,如果是由条件得到 Permission表中的name,那么
    sql= select Name from Permission  where ID=(select PermissionID from serAccountXPermission where UserAccountID=(select ID from UserAccount where UserName=?)) 
      

  9.   

    会不会是根本没有连接上数据库
     at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
      

  10.   

    http://blog.sina.com.cn/s/blog_6380d05001010roj.html
      

  11.   

    执行完sql语句后,ResultSet 对象的游标是指向第0行的,当你调用一次rs.next()时,就往下移动,变成1,你取数据是从第1行开始的,所以你在真正调用rs.getString()之前一定要调用rs.next()方法,如果不调用的话,rs.getString取的就是第0行,肯定会有问题的。
      

  12.   

    是result没有打开,
     rs = ps.executeQuery();  
    rs.next();
      str = rs.getString("name");        
      

  13.   

    SQL语句直接写错了..   
      

  14.   

     Before start of result set 记录指针位置在记录头,要Next一下