标题:JDBC问题
只看楼主
亮剑
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2006-10-18
 问题点数:0 回复次数:3 
JDBC问题


public ArrayList findUserByAll() {
String sql1 = \"select id,user_name,password from user\";
String sql2 = \"select b.actor_name,c.droit_name\"
+ \"from user as a,actor as b,droit as c,user_actor_droit as d \"
+ \"where b.id = d.actor_id and c.id = d.droit_id and a.id = ?\";
try {
ps = con.prepareStatement(sql1);
ResultSet result1 = ps.executeQuery();
ArrayList<User> users = new ArrayList<User>();
while(result1.next()){
User user = new User();
user.setId(result1.getString(1));
user.setName(result1.getString(2));
user.setPassword(result1.getString(3));
Actor actor = new Actor();
actor.setUser(user);
PreparedStatement ps1 = con.prepareStatement(sql2);
ps1.setString(1, user.getId());
ResultSet result2 = ps1.executeQuery();

actor.setName(result2.getString(1));
ArrayList droits = new ArrayList();
while(result2.next()){
Droit droit = new Droit();
droit.setName(result2.getString(2));
droits.add(droit);
}
user.setActor(actor);
users.add(user);
}
return users;
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}



=========================为什么会有下面的错误啊 我直接把SQL 语句复制到数据库端执行没有错误=======


java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as a,actor as b,droit as c,user_actor_droit as d where b.id = d.actor_id and c.i' at line 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2994)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:936)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1030)
at com.chen.dao.UserDao.findUserByAll(UserDao.java:91)
at com.chen.dao.test.UserTest.testfindUserByAll(UserTest.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

[此贴子已经被作者于2007-7-20 13:51:01编辑过]



NuDYuS5t.jpg (43.68 KB)
搜索更多相关主题的帖子: droit JDBC actor name 
2007-07-20 11:16
lgdcky
Rank: 2
等 级:论坛游民
威 望:5
帖 子:576
专家分:18
注 册:2006-8-5
得分:0 
You have an error in your SQL syntax!

2007-07-20 16:29
野蛮女人
Rank: 5Rank: 5
等 级:贵宾
威 望:19
帖 子:827
专家分:0
注 册:2007-4-7
得分:0 
小兄弟
String sql2 = "select b.actor_name,c.droit_name"《这是不是少了个空格啊》
+ "from user as a,actor as b,droit as c,user_actor_droit as d "
+ "where b.id = d.actor_id and c.id = d.droit_id and a.id = ?";

[shadow=255,purple,5]好人不长命,祸害一万年![/shadow]
2007-07-20 23:54
野蛮女人
Rank: 5Rank: 5
等 级:贵宾
威 望:19
帖 子:827
专家分:0
注 册:2007-4-7
得分:0 

[shadow=255,purple,5]好人不长命,祸害一万年![/shadow]
2007-07-20 23:54



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-156806-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.284194 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved