| | |
java.sql.SQLException: Column 'XXXXXX' not found.
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 10
Reputation:
Solved Threads: 0
JSP Syntax (Toggle Plain Text)
package Add; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionForward; public class AddSuccessAction extends Action { private final static String SUCCESS = "success"; public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { MyBean bean = (MyBean) form; String cityName = bean.getCn(); String pincode = bean.getPc(); Connection con = null; ResultSet rs = null; PreparedStatement stmt = null; String connectionURL = "jdbc:mysql://localhost:3306/city"; try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection (connectionURL,"root","welcome12#"); String sq = "SELECT city_name,pincode from data "; stmt = con.prepareStatement(sq); rs = stmt.executeQuery(); boolean flag = false; while (rs.next()) { String pic = rs.getString(pincode); if(pic=="pincode") { System.out.println("Pincode already exists"); flag = true; } } if(!flag) { String sql = "INSERT INTO city (city name,pincode) VALUES('"+cityName+','+pincode+"')"; stmt = con.prepareStatement(sql); stmt.executeUpdate(); } } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { stmt.close(); con.close(); } return mapping.findForward(SUCCESS); } }
0
#2 Oct 13th, 2009
JSP Syntax (Toggle Plain Text)
String pic = rs.getString("pincode");
JSP Syntax (Toggle Plain Text)
String pic = rs.getString(pincode);
Also, use a preparedStatement, cobbling a statement together using String concatenation like you've done is just begging for trouble. Maybe only as innocent as a mistyped user input string that causes the SQL to fail with a syxntax error, or as damaging as an intentional SQL Injection attack.
Edit: And this
JSP Syntax (Toggle Plain Text)
if(pic=="pincode")
Last edited by masijade; Oct 13th, 2009 at 6:49 am.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
-1
#3 Oct 13th, 2009
Edit: Ignore this, masijade already spotted error
First check your name spelling for tables and columns used if you have any spelling mistakes (can check it as you failed to provide database or affected tables specs)
In the future please post full error message not just section.
First check your name spelling for tables and columns used if you have any spelling mistakes (can check it as you failed to provide database or affected tables specs)
In the future please post full error message not just section.
Last edited by peter_budo; Oct 13th, 2009 at 6:49 am. Reason: Edit
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Oct 2009
Posts: 10
Reputation:
Solved Threads: 0
0
#4 Oct 13th, 2009
•
•
•
•
notJSP Syntax (Toggle Plain Text)
String pic = rs.getString("pincode");
JSP Syntax (Toggle Plain Text)
String pic = rs.getString(pincode);
Also, use a preparedStatement, cobbling a statement together using String concatenation like you've done is just begging for trouble. Maybe only as innocent as a mistyped user input string that causes the SQL to fail with a syxntax error, or as damaging as an intentional SQL Injection attack.
Edit: And this
is probably backwards, too.JSP Syntax (Toggle Plain Text)
if(pic=="pincode")

i am a newbie.
thanks for replying neways.
![]() |
Similar Threads
- java.sql.SQLException: Column not found (Java)
- JSP :java.sql.SQLException: ORA-01722: invalid number (JSP)
- Derby Connection Issues (Java)
- JAVA Sql error: Column not found (Java)
- MySQL error java.sql.SQLException: Parameter index out of range (0 < 1 ). (Java)
- No suitable driver found for jdbc:mysql://.... on jsf page (JSP)
- error while retroeving data from mqsql database (JSP)
- java.sql.SQLException: Invalid column index (Java)
- Error java.sql.SQLException: [Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle (Java)
Other Threads in the JSP Forum
- Previous Thread: problem in comparision of dropdown value and database vale
- Next Thread: checkbox value
| Thread Tools | Search this Thread |
apache array backbutton combobox comma connection csv database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient read redirect request.getparameter response seperated servlet servletdopost()readxml sessions software sql ssl state_saving_method stocks sun tomcat tutorial update values video web write






