i written this query (in java class) to select some information from the MySQL database
and view it on jsp page...
SELECT instructor.name FROM
instructor,section,teach WHERE
teach.student_id='3'AND teach.section
= section.number AND section.instructor_id= instructor.ID
but there is exception was occur!
javax.servlet.ServletException:
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
'.student_id='3'AND teach.section =
section.number AND
section.instructor_id= ins' at line 1
,,
by the way, i was write it in PhpMyAdmin, and it's work..
App server: Sun GlassFish Enterprise Server v2.1
please help me...
Regards
You need a space after the '3'.
It seems that there is a space missing. '.student_id='3'AND -> '.student_id='3' AND
If your query is exactly as you show it:
SELECT instructor.name FROM instructor,section,teach WHERE teach.student_id='3'AND
teach.section = section.number AND section.instructor_id= instructor.ID
then you need a space after the '3' and before AND on the first line shown above.
What is the datatype of "teach.student_id"? Is it numeric or varchar. If it is numeric, no need to put the '3' inside single quotes.
e.g.
teach.student_id = 3
Thanks for all
i was write query in java class like this
ResultSet rs
=stmt.executeQuery("SELECT instructor.name " +
"FROM instructor,section,teach" +
"WHERE teach.student_id=" + "'" + idd + "'" +
" AND teach.section = section.number
AND section.instructor_id=
instructor.ID");
then i eliminate all lines, and put query in one line like this, then it's solved...
Regards
Related
just kinda struggling with identifying the id during the piece update. I pass the id as a var and am trying to use it in conjunction with the WHERE statement and cant seem to figure out the correct syntax
String update = "UPDATE LawnMowers"+ " SET LMPrice = '"+returnedPrice+"' " + " WHERE LMID = '"+returnedID+'";
the return id is the issue, and the error is "invalid character constant". I believe the issue is normally the statement would be:
"WHERE LMID = int/double.ect"; rather then using " WHERE LMID = '"+varr+'"; errors and adding the additional " or )" ect options I have tried dont work either. Just wondering if any one had some insight
my DB is on Godaddy
thanks for reading
I think your statement should end
+ returnedID + "'";
Yours currently ends
+returnedID+'";
Also please read about prepared statements, these are much easier to use and leave you at far less risk of SQLi security vulnerabilities. It would look something like this:
String update = "UPDATE LawnMowers SET LMPrice = ? WHERE LMID = ?";
updateStatement = con.prepareStatement(update);
updateStatement.setInt(1, returnedPrice);
updateStatement.setInt(2, returnedId);
updateStatement.executeUpdate();
I am working on test environment.
Here is the query which I used in java
String sql = "INSERT INTO PO_PART_XML_IF (INTERFACE_ID, INTERFACE_TRANSACTION_ID,"
+ " O_SEQ_NO, PART_NO, O_QTY, O_TYPE_CODE, R_R_NO"
+ " ,O_LINE_COMMENT, C_CODE, INPUT_USER_ID, INPUT_TIMESTAMP, "
+ "LAST_UPDATE_USER_ID, LAST_UPDATE_TIMESTAMP ) VALUES (
G_REPAIR_PARTS_IF_SEQ.nextval,"+transactionnumber+",'"+orderSecNo+"','"+
job.getPartNo()+"',"+ Long.parseLong(job.getOrderQty())+",'"+job.getDeliveryType().getTitle()+"','"+job.getServiceReceiptNo()+"','"+replaceSingleQuote(job.getOrderComment())+"','"+currencyCode+"','"+inputUserID+"',SYSDATE,'"+inputUserID+"',SYSDATE)";
When I did some test then I got this error in log files :
org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
I checked directly on pl/sql, It is working fine.I mean insert data. but when you test with java program, it show me this error.
Any Idea!
If the query is ok (you'll have to check that), the code which should work is
Statement statement = dbConnection.createStatement();
statement.executeUpdate(sql);
You are probably using
statement.executeQuery(sql);
which is wrong for insert query.
You haven't shown the code that actually executes the query, but judging by the message it seems you are executing as if it returns data, ie a SELECT, but it's an UPDATE statement.
Try executing it using the appropriate API for an update.
When I try to execute:
SELECT matricula FROM lss_alumnos WHERE lss_alumnos.division = 'PREP';
I get this message:
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 '.division = 'PREP'' at line 1
And I am also using MySQL Workbench, and there I got the right result.
Try removing the qualified name lss_alumnos before the column name, also, remove the leading ;.
SELECT `matricula` FROM `lss_alumnos` WHERE `division` = 'PREP'
(It's also a good practice to surround the names with the ` symbol).
I believe the comments are closer to the truth than the only other answer. To be sure, this query will work:
SELECT la.`matricula` FROM `lss_alumnos` la WHERE la.`division`='PREP'
Edit: I checked. None of these words are a MySQL reserved word http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html. It must be the semicolon
We have a database code in place for a long time which is running successfully with Progress DB. Recently, we tried it with SQL Server 2008 with JDBC 4 driver .It gave below exception:
Database '%' does not exist. Make sure that the name is entered correctly.
DatabaseMetaData conMD = connection.getMetaData();
ResultSet columns = conMD.getColumns("%", "%", m_Table, "%");
Could anybody please help me out ?
If you get the list of catalogs before?
With the method getCatalogs()
http://download.oracle.com/javase/1.4.2/docs/api/java/sql/DatabaseMetaData.html#getCatalogs()
As the error message says: you cannot pass a wildcard for the database (catalog) parameter. Wildcards are only allowed for the schema, table and column names.
Use null instead.
conMD.getColumns(null, "%", m_Table, "%");
conMD.getColumns(connnection.getCatalog(), "%", m_Table, "%");
instead of giving % ,connnection.getCatalog()will fix the issue.Interesting thing is that the code works with Oracle,MySql and Progress . Only Sql Server is throwing the error.
I am trying to use a Java application (which I do not have the source code for) to output the results of a call to a stored procedure into a text file.
This file works for other similar stored procedures in the system, but I can't seem to get it to produce anything for my new text file other than this exception:
ResultSet is from UPDATE: No Data
I've simplified the body of the stored procedure to a simple select 'Hello World!' and even that doesn't seem to be able to be written out.
Is there anything I can do within the stored procedure to produce results in a fashion that Java will accept?
I encountered this java.sql.SQLException. In my case I was running a query in this way:
String query =
"-- a classical comment " +
"select * " +
"from MYTABLE ";
ResultSet rs = conMain.createStatement().executeQuery(query);
while(rs.next()) {
//do something...
}
rs.next() throws the exception. The reason is that, due to the comments, query results to be:
"-- a classical comment select * from MYTABLE "
hence it's all commented... query is invalid! Many examples could be shown with this mistake (with the comment in the middle of the query etc.).
Solutions: add a \n at the end of each line of the query or use comments in the /*...*/ form.
I selected an older version of the driver an it worked for me.
http://dev.mysql.com/downloads/mirror.php?id=13598 (mysql-connector-java-5.0.8.zip)