電子書籍の厳選無料作品が豊富!

Eclipseで入力した内容からテーブル内を検索して結果を出すプログラムを作っていますが、エラーを起こしてしまいます。

<Javaソース抜粋>
try{
String sql = "select * from student_table where id like= '*" + student.getid() + "*' and student_name like = '*" + student.getstudent_name() + "*' and student_adress like = '*" + student.getstudent_adress() + "*' and student_tel like = '*" + student.getstudent_tel() + "*' and student_birthday like = '*" + student.getstudent_birthday() + "*' and student_entrance like = '*" + student.getstudent_entrance() + "' and student_sex = '" + student.getstudent_sex() + "*' and student_subject = '" + student.getstudent_subject() + "'";

<エラー内容>
com.mysql.jdbc.exceptions.jdbc4.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

どうもこのselect文が問題を起こしているらしいのですが、何がなんだかさっぱりです
どなたかヒントをいただけませんか?

A 回答 (3件)

SQL内のlikeの使い方が間違っています。



×
select *
from student_table
where id like = '*1234*'
(*はワイルドカードのつもりでしょうか?)


select *
from student_table
where id like '%1234%'

参考URL:http://www.dbonline.jp/mysql/select/index7.html
    • good
    • 0

あ、+もいるね。

    • good
    • 0

String sql = "select * from student_table where id like= '*" + student.getid() + "*' and<"> student_name like = '*" +



<>の中の"が抜けている。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!