Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
String sql="insert into std(StudentID,Surname,Name,CourseCode,Maths,English,Physics,Biology,Chemistry,Psychology,HealthScience,Religion"+"TotalScore,Average,Ranking)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";`
` try{
`pst=conn.prepareStatement(sql);`
`pst.setString`(1, jTextField14.getText());`
` pst.setString(2, jTextField1.getText());`
` pst.setString(3, jTextField2.getText());`
` pst.setString(4,(String) jComboBox1.getSelectedItem());`
` pst.setString(5, jTextField6.getText());`
`pst.setString(6, jTextField7 .getText());`
` pst.setString(7, jTextField8.getText());`
` pst.setString(8, jTextField9.getText());`
`pst.setString(9, jTextField10.getText());`
`pst.setString(10, jTextField11.getText());`
` pst.setString(11, jTextField12.getText());`
` pst.setString(12, jTextField13.getText());`
`pst.setString(13, jTextField3.getText());`
`pst.setString(14, jTextField4.getText());`
` pst.setString(15, jTextField5.getText());`
`pst.execute();`
`JOptionPane.showMessageDialog(null, "system update completed");`
`rs.close();`
` pst.close();`
`}catch(Exception e){`
`JOptionPane.showMessageDialog(null, e);`
` }`
` } `
i keep getting this error error in sql syntax check for error that corresponds to mysql manual near
Although the error message is missing, it's probably in consequence of calling an incompatible setter method for one or more parameters.
For example, an id column is usually a number. Hence, based on the data type of this column, you have to call the corresponding setter method (setInt, setLong).
To get more information about PreparedStatements and its methods, read this document:
docs.oracle.com:PreparedStatement.html
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
This is my database table call "BREAKFAST_TABLE" I want to keep date that not duplicate to list
This is my code
public List<String> get_notSameDate(String status)
{
List<String> return_Food=new ArrayList<>();
//COLUMN_DATE is "DATE"
//status is "BREAKFAST_TABLE"
String queryString="SELECT DISTINCT"+COLUMN_DATE+" FROM "+status;
SQLiteDatabase db=this.getReadableDatabase();
Cursor cursor = db.rawQuery(queryString,null);
if(cursor.moveToFirst())
{
do {
String date=cursor.getString(0);
return_Food.add(date);
}while (cursor.moveToNext());
}
cursor.close();
db.close();
return return_Food;
}
I using this code it always crashes.
Though we don't know what error it crashes with, I believe it fails because of missing space symbol between "DISTINCT" and the column name:
"SELECT DISTINCT"+COLUMN_DATE+" FROM "+status;
fixed:
"SELECT DISTINCT "+COLUMN_DATE+" FROM "+status;
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
PreparedStatement amovie = con.prepareStatement("INSERT INTO actor_movie(actor_ID, movie_ID)"+ "select actor_ID from actor" + "where actor.surname = 'Depp', select movie_ID from movie where movie.title LIKE 'Caribbean%'");
Can someone tell me what is wrong with this query ? I digged the internet, but can't find a solution.
Error Message :
Exception in thread "main" 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 movie_ID from movie where title LIKE 'Caribbean%'' at line 1
You have syntax error because you forgot VALUES and to enclose in parentheses the SELECT statements.
Change to this:
PreparedStatement amovie = con.prepareStatement(
"INSERT INTO actor_movie(actor_ID, movie_ID) VALUES ((select actor_ID from actor where actor.surname = 'Depp'), (select movie_ID from movie where movie.title LIKE 'Caribbean%'))");
Careful with the spaces needed between the strings concatenate
...movie_ID)"+ "select ...
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
My columns at customer table
cusid cusname cusadress paidamount email
cus123 damidu kegalle 45 adfff
This is my Java query
String query = "UPDATE `customer` SET `cusname`='"+jTextField_name.getText()+"',`cusadress`='"+jTextField_adress.getText()+"',`paidamount`='"+jTextField_amount.getText()+"',`email`="+jTextField_emailuser.getText()+" WHERE `cusid` = "+jTextField_id.getText();
executeSQlQuery(query, "Updated");
Error
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'cus123' in 'where clause'
What is the reason for this update is not working , but insert and delete statement works?
Use PreparedStatement like this below :
String updateQuery = "UPDATE customer SET cusname=?,cusadress=?,paidamount=?,email=? WHERE cusid=?";
PreparedStatement stmt=con.prepareStatement(updateQuery); // con is reference variable of Connection class
stmt.setString(1, jTextField_name.getText());
stmt.setString(2, jTextField_adress.getText());
stmt.setInt(3, jTextField_amount.getText());
stmt.setString(4, jTextField_emailuser.getText());
stmt.setString(5, jTextField_id.getText());
Hope this helps.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm getting this error when I'm trying to connect my Java Plugin to the local MySQL database:
[01:15:44 INFO]: [BetterStaff] Could not connect to database: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 ''Reportslog' ('SenderName' varchar(32), 'Message' string)' at line 1
The code from my plugin is:
this.db.openConnection();
Statement statement = this.db.getConnection().createStatement();
statement.executeUpdate("CREATE TABLE IF NOT EXISTS 'Reportslog' ('SenderName' varchar(32), 'Message' string)");
Can you help me or correct my SQL syntax please?
Quotes are not allowed in the table name or fields:
String sql =
"CREATE TABLE IF NOT EXISTS Reportslog (SenderName varchar(32), Message varchar(32))";
PreparedStatement preparedStatement = conn.prepareStatement(sql);
preparedStatement.executeUpdate();
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Below code gives
ORA-00933: SQL command not properly ended
on
private final String DUPLICATE_SQL_1="select abc, count(abc)"
+"from table_1"
+"where type= 'NEW'"
+"and trunc(update_date) = trunc(sysdate)"
+"group by abc having count(abc)>1";
ResultSet rs = stmt.executeQuery(DUPLICATE_SQL_1);
Same query worked fine on Oracle SQL Developer.
You are missing spaces (you must have a space at the end of each line except the last or at the start of each line except the first):
private final String DUPLICATE_SQL_1="select abc, count(abc) "
+"from table_1 "
+"where type= 'NEW' "
+"and trunc(update_date) = trunc(sysdate) "
+"group by abc having count(abc)>1";