SQLServer Exception: Invalid column name
exception, java, jdbc, sql, sql-server-2012
Solution
Remove quotes , try :
String query = "INSERT INTO Paciente(IDPaciente, NomePaciente, IdadePaciente, LocalidadePaciente) VALUES('"+IDTextField.getText()+"', '"+NomeTextField.getText()+"', '"+IdadeTextField.getText()+"', '"+LocalidadeTextField.getText()+"')";
try
{
st = con.DatabaseConnection().createStatement();
rs = st.executeQuery(query);
}
Remove also quotes for `INT` values.
Problem
``` com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'IDPaciente' ``` I am getting this exception. This is my code: ``` String query = "INSERT INTO Paciente('IDPaciente', 'NomePaciente', 'IdadePaciente', 'LocalidadePaciente') VALUES('"+IDTextField.getText()+"', '"+NomeTextField.getText()+"', '"+IdadeTextField.getText()+"', '"+LocalidadeTextField.getText()+"')"; try { st = con.DatabaseConnection().createStatement(); rs = st.executeQuery(query); } ``` I suspect the problem might be in the query itself. I have searched a lot and couldn't find the solution to my problem. I have tried refreshing the cache, changing permissions within the schema, restarting sql server (I am using sql server management studio 2012), I am correctly connected to my database, and nothing seems to work. What could I be doing wrong? Thank you!