【发布时间】:2016-10-18 02:59:22
【问题描述】:
我正在尝试从 Eclipse 运行此查询:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
HttpSession session = request.getSession();
String name = session.getAttribute("user").toString();
String query = "SELECT DISTINCT t.text, t.user, t.date"
+ " FROM users u, tweets t, follows f"
+ " Where t.parent is null"
+ " AND u.id ="+name
+ " AND ( f.follower = u.id"
+ " AND f.followed = t.user"
+ " OR t.user = u.id)"
+ " ORDER BY t.date DESC;";
但我收到以下错误:
Sesion(user):Takeshi
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'Takeshi' in 'where clause'
我可以想象这个错误是因为我做错了 u.id 和 name 之间的比较,但我应该怎么做呢?有一些特殊的性格?提前致谢。
【问题讨论】:
-
你的连接错误;试试这个
+ " AND u.id = '" + name + "'"
标签: java mysql sql eclipse jdbc