I tried to write a insert statement with Spring JDB Template for an PostgreSQL Database. My insert string looked like this:
final String sql = "INSERT INTO products (prod_name, prod_key, artifact_id,
group_id, link, src, prod_type) VALUES ('?','?','?','?','?','?','?')";
And I got this Exception:
PreparedStatementCallback; SQL []; The column index is out of range: 1,
number of columns: 0.; nested exception is org.postgresql.util.PSQLException:
The column index is out of range: 1, number of columns: 0.
Solve:
The Problem was that I used ” ‘ ” inside of the sql string close to
the “?”. After I removed the ” ‘ ” strings it worked perfectly.
Wednesday, 27 November 2013
How to convert java.util.date to java.sql.date?
public class MainClass {
public static void main(String[] args) {
java.util.Date utilDate = new java.util.Date();
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
System.out.println("utilDate:" + utilDate);
System.out.println("sqlDate:" + sqlDate);
}
}
explains it. The link is http://www.java2s.com/Tutorial/Java/0040__Data-Type/ConvertfromajavautilDateObjecttoajavasqlDateObject.htm
Source: http://stackoverflow.com/questions/530012/how-to-convert-java-util-date-to-java-sql-date
Wednesday, 13 November 2013
Passing clicked value from jsp to jsp/servlet
We can pass the value from jsp to servlet using,
Passing clicked value from jsp to jsp/servlet:
We have to pass the clicked value as get parameter in the href link like below,
Servlet code:
In the below sample program javadomain (small letters) will be clicked, then the same value passed from jsp to servlet and there javadomain(small letters) are converted to JAVADOMAIN (UPPER CASE) then the new upper case values are passed from servlet to jsp.
Program:
main.jsp:
Output:
Source: http://javadomain.in/passing-clicked-value-from-jsp-to-jspservlet/
Thanks for reading this post……..!!!
request.getParameter("text"); //servlet code to get the jsp valuewhere text is the name of the input fields (text field).
Passing clicked value from jsp to jsp/servlet:
We have to pass the clicked value as get parameter in the href link like below,
<a href="/Myservlet?input=javadomain">MyServlet is the name of the servlet.
Servlet code:
request.getParameter("input");So javadomain will be passed from jsp to servlet.
In the below sample program javadomain (small letters) will be clicked, then the same value passed from jsp to servlet and there javadomain(small letters) are converted to JAVADOMAIN (UPPER CASE) then the new upper case values are passed from servlet to jsp.
Program:
main.jsp:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <html> <head> <title>Small Letters</title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta name="GENERATOR" content="Rational Application Developer"> </head> <body> <a href="/Blog/ToCapLetters?a=javadomain">javadomain</a> </body> </html>final.jsp:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <html> <head> <title>Capital Letters</title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta name="GENERATOR" content="Rational Application Developer"> </head> <body> <% HttpSession session1 = request.getSession(); String capitalValue = session1.getAttribute("clicked_value").toString(); out.println(capitalValue); %> </body> </html>ToCapLetters.java: (servlet file)
import java.io.IOException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; /** * Servlet implementation class ToCapLetters */ @WebServlet("/ToCapLetters") public class ToCapLetters extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public ToCapLetters() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String value = request.getParameter("a"); String value_capital = value.toUpperCase(); HttpSession session = request.getSession(); session.setAttribute("clicked_value", value_capital); RequestDispatcher rd = request.getRequestDispatcher("./final.jsp"); rd.forward(request,response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } }
Output:
Source: http://javadomain.in/passing-clicked-value-from-jsp-to-jspservlet/
Thanks for reading this post……..!!!
Subscribe to:
Posts (Atom)