我要做的是更新它将搜索itemnumber的记录,并使用id来根据edittext中的内容更改另一个表中的shelfnumber
这是我尝试更新记录时遇到的错误
java.sql.SQLException:关键字“file”附近的语法不正确。
这发生在我的公共课和我的preparedStatement.executeUpdate();
public class UpdatePro extends AsyncTask<String, String, String> {
String z = "";
Boolean isSuccess = false;
String item = cardnumberbox.getText().toString();
String shelf = shelfnumberbox.getText().toString();
@Override
protected String doInBackground(String... params) {
if (item.trim().equals("") || shelf.trim().equals(""))
z = getString(R.string.Invalid_Credentials);
else {
try {
Connection con = connectionClass.CONN();
if (con == null) {
z = getString(R.string.Forbindelses_fejl);;
} else {
String text1 = item;
{
if(text1.substring(0,1).startsWith("K"))
{
text1 = text1.substring(1);
}
else
{
text1= text1 ;//.substring(0));
}
}
String text2 = shelf;
{
if(text2.substring(0,1).startsWith("R"))
{
text2 = text2.substring(1);
}
else
{
text2= text2 ;//.substring(0));
}
}
String query = "Update PS set ShelfNumber = "+text2+ " from file.ItemPart PS "+ " join file.item P on P.id = PS.id "+ " where P.ItemNumber = '"+text1 + "'";
PreparedStatement preparedStatement = con.prepareStatement(query);
preparedStatement.executeUpdate();
z = getString(R.string.Update_succes);
isSuccess = true;
}
} catch (Exception ex) {
isSuccess = false;
Log.e("YOUR_APP_LOG_TAG", "I got an error", ex);
z = getString(R.string.Exceptions);
}
}
return z;
答案 0 :(得分:0)
尝试:
public class UpdatePro extends AsyncTask<String, String, String> {
String z = "";
Boolean isSuccess = false;
String item = cardnumberbox.getText().toString();
String shelf = shelfnumberbox.getText().toString();
@Override
protected String doInBackground(String... params) {
if (item.trim().equals("") || shelf.trim().equals(""))
z = getString(R.string.Invalid_Credentials);
else {
try {
Connection con = connectionClass.CONN();
if (con == null) {
z = getString(R.string.Forbindelses_fejl);;
} else {
String text1 = item;
{
if(text1.substring(0,1).startsWith("K"))
{
text1 = text1.substring(1);
}
else
{
text1= text1 ;//.substring(0));
}
}
String text2 = shelf;
{
if(text2.substring(0,1).startsWith("R"))
{
text2 = text2.substring(1);
}
else
{
text2= text2 ;//.substring(0));
}
}
String query = "Update PS set ShelfNumber = "+text2+ " from [file].[ItemPart] PS "+ " join [file].[item] P on P.id = PS.id "+ " where P.ItemNumber = '"+text1 + "'";
PreparedStatement preparedStatement = con.prepareStatement(query);
preparedStatement.executeUpdate();
z = getString(R.string.Update_succes);
isSuccess = true;
}
} catch (Exception ex) {
isSuccess = false;
Log.e("YOUR_APP_LOG_TAG", "I got an error", ex);
z = getString(R.string.Exceptions);
}
}
return z;