麻烦各位大神帮我看看,我在查询单个女神为啥老是报下面的异常?

来源:2-5 JDBC实战---搭建模型层 Ⅲ

D布克

2016-02-03 14:49

Exception in thread "main" com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: 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 '=1' at line 1

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)

at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)

at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)

at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1467)

at com.imooc.dao.GoddessDao.get(GoddessDao.java:96)

at com.imooc.action.GoddessAction.main(GoddessAction.java:35)


package com.imooc.action;


import java.util.Date;

import java.util.List;


import com.imooc.dao.GoddessDao;

import com.imooc.model.Goddess;


public class GoddessAction {

     public static void main(String[] args) throws Exception {

GoddessDao g=new GoddessDao();


/** List<Goddess> gs=g.query();

for (Goddess goddess : gs) {

System.out.println(goddess.getUser_name()+","+goddess.getAge());

}

**/

// Goddess g1=new Goddess();

//

// g1.setUser_name("小夏");

// g1.setAge(22);

// g1.setSex(1);

// g1.setBirthday(new Date());

// g1.setEmail("xiaoxia@imooc.com");

// g1.setMobile("18766123456");

// g1.setCreate_user("ADMIN");

// g1.setUpdate_user("ADMIN");

// g1.setIsdel(1);

// g1.setId(4);

// g.addGoddess(g1);

// g.updateGoddess(g1);

// g.delGoddess(3);

Goddess g2=g.get(1);

System.out.println(g2.toString());

}

 }


写回答 关注

1回答

  • D布克
    2016-02-03 15:28:59

    不好意思,太粗心了,原来是空格的问题,原因是“select * from imooc_goddesswhere id=?”,imooc_goddesswhere这两没有空格连在一起啦

JDBC之 “ 对岸的女孩看过来”

一起领略JDBC的奥秘,为进一步学习集成框架打下良好的基础

99324 学习 · 856 问题

查看课程

相似问题