Skip to content Skip to sidebar Skip to footer

The Column Name Is Not Valid - Error

I am getting this error while I am fetching value from resultset. Error : com.microsoft.sqlserver.jdbc.SQLServerException: The column name company.short_name is not valid CASE

Solution 1:

resultset.getString("company.short_name"); is wrong here. No need to specifying fully qualified name while trying to fetch the data in your application. Just specify the column name like resultset.getString("short_name");.

Cause even though you say select company.short_Name ... query out the column name as short_Name since that's what defined in table schema.

In case both tables has same column which may result in ambiguity, give a alias name to the columns like

select company.short_Name as company_shortname,
       location.short_Name as location_shortname,
location.location_name from company,location;

Solution 2:

When you do

select company.short_Name,location_name from company,location;

This query outs the column name short_Name and resultSet would also have short_Name

since the company.short_name doesnt exist you get an error.

Solution 3:

add the following to your application.properties file spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

Solution 4:

the function resultset.getString(String columnLabel)

Retrieves the value of the designated column in the current row of this ResultSet object as a String in the Java programming language.

Parameters:

columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column

Returns:

the column value; if the value is SQL NULL, the value returned is null Throws: SQLException - if the columnLabel is not valid; if a database access error occurs or this method is called on a closed result set

in the function resultset.getString(String columnLabel), the arg is a column name for executing sql, the statement select company.short_Name,location_name from company,location; will get a result set, which has table headers short_Name,location_name

Post a Comment for "The Column Name Is Not Valid - Error"