Danny Baquilod

Greenhorn
+ Follow
since Jun 26, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Danny Baquilod


Hello,

I'm getting the ERROR below when I run my simple application from Netbeans. I am using Tomcat and I just installed it separately after Netbeans installation.

Can anyone free to assist? Thank in advance.

===========
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path
==========

Danny
10 years ago

Rob Spoor wrote:

Danny Baquilod wrote:java.lang.NullPointerException
at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1235)
at java.text.DateFormat.parse(DateFormat.java:335)
at AddUser.doPost(AddUser.java:80)


The only parsing I see is that of dateCreate which is initialized here:
This error indicates that dateCreate is null, which means that the parameter is not present.




Yes, that's the culprit
Thanks Rob. It's working now :)

Paul Clapham wrote:That probably means that something was null in a place which can't handle nulls. Unfortunately you don't know where that place is, because when you printed the exception you didn't print that information. So take line 60 and print the stack trace:

(There's no point in printing the word "Error", when you see the stack trace you'll know that an error occurred anyway.)

The stack trace will tell you what line of your code threw the exception, so start there.



Ok, now after I've e.printStackTrace I got the following error :
java.lang.NullPointerException
at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1235)
at java.text.DateFormat.parse(DateFormat.java:335)
at AddUser.doPost(AddUser.java:80)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)







Hello, can somebody help.
I can't insert data into table and it thows null message.
Netbeans displays : Error null (captured at the Exception)

I used the same script for other servlet to insert to other table and it is working fine.

Thanks in advance
Danny

========================================
1.) import java.io.IOException;
2.) import java.io.PrintWriter;
3.) import javax.servlet.ServletException;
4.) import javax.servlet.http.HttpServlet;
5.) import javax.servlet.http.HttpServletRequest;
6) import javax.servlet.http.HttpServletResponse;
7) import java.sql.*;
8) import java.text.DateFormat;
9) import java.text.ParseException;
10) import java.text.SimpleDateFormat;
11) import java.util.Date;
12)
13) public class AddUser extends HttpServlet {
14) Date newDate;
15)
16) protected void processRequest(HttpServletRequest request, HttpServletResponse response)
17) throws ServletException, IOException {
18) response.setContentType("text/html;charset=UTF-8");
19) PrintWriter out = response.getWriter();
20)
21) String userId = request.getParameter("txtUserId");
22) String userName = request.getParameter("txtUserName");
23) String dept = request.getParameter("txtDept");
24) String costCenter = request.getParameter("txtCostCenter");
25) String desig = request.getParameter("txtDesig");
26)
27) try {
28) Class.forName("oracle.jdbc.driver.OracleDriver");
29) String serverName = "localhost";
30) String portNumber = "1521";
31) String sid = "dbsin";
32) String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
33) String username = "wpjfk";
34) String password = "wpjfk";
35) Connection conn = DriverManager.getConnection(url, username, password);
36)
37) Statement stmt = conn.createStatement();
38) String sql = "insert into sys_user_mast values (?,?,?,?,?,?)";
39) PreparedStatement pst = conn.prepareStatement(sql);
40)
41) String dateCreate = request.getParameter("dateCreate");
42) SimpleDateFormat formater = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
43) Date dateCreated = formater.parse(dateCreate);
44) newDate = dateCreated;
45)
46) pst.setString(1, userId);
47) pst.setString(2, userName);
48) pst.setString(3, dept);
49) pst.setString(4, costCenter);
50) pst.setString(5, desig);
51) pst.setDate(6, new java.sql.Date(newDate.getTime()));
52)
53) int numRowsAdded = pst.executeUpdate();
54)
55) out.println(" Record saved successfully : "+numRowsAdded);
56) pst.close();
57)
58)
59) }catch (Exception e){
60) System.out.println("Error"+e.getMessage());
61)
62) } finally {
63) out.close();
64
65 }


}


Rob Spoor wrote:Well, you got the parsing correct. Now all you need to do is turn a java.util.Date object into a java.sql.Date object:
Likewise for java.sql.Time and java.sql.Timestamp.



Thanks Rob, now it works

Rob Spoor wrote:

Danny Baquilod wrote:

Rob Spoor wrote:Use DateFormat / SimpleDateFormat and their parse methods.




Thanks. Would you mind putting the script here?


Please SearchFirst. There are millions of examples on the Internet, including hundreds (if not thousands) on the Ranch itself.



Here's the script :







1. try {
2. String dateCreate = request.getParameter("dateCreate");
3.
4. SimpleDateFormat formater = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
5.
6. Date dateCreated = formater.parse(dateCreate);
7. newDate = dateCreated;
8. } catch (ParseException e )
9. {
10. e.printStackTrace();
11. }
12.
13. pst.setDate(6, newDate);
at line 13, it shows an error below.
// cannot find symbol
// symbol: method setDate(int, java.util.Date)
// location: interface java.sql.PreparedStatement

thanks in advance.

Rob Spoor wrote:Use DateFormat / SimpleDateFormat and their parse methods.




Thanks. Would you mind putting the script here?

I should start by getting the string from JSP...

String entryDate = request.getParameter("dEntryDate");

I tried doing that method from other forum but still getting error. THanks.

Since we have the same issue, i'd rather use this topic to post my question.

//Servlet

String entryDate = request.getParameter("dEntryDate");

//How should I convert the above entryDate String to date? I need it to save to database table using setDate().


pst.setDate(34, dEntryDate);

Thanks in advance for your help.

Daniel

Bear Bibeault wrote:Java code and a result set in a JSP?

In an case, you should be looking at the HTML thtas generated rather than thesaource code.

But, your href is missing the contex path,and why does it have the host part of the URL? Is it in a separate web app?



Hi, I understand your "shock" reaction. I will change that later on. I'm just starting to move to MVC Thanks for calling my attendtion.

Here is my problem again:
My code is in JSP displaying a table(list of data) and would like to call a servlet and passing a parameter. I tried to google it but I got some answer that I have to include the URL but I'm not sure if I'm getting it right.

In a servlet I would be calling a bean class to set the data and forward to JSP to display it for editing.

Thanks.
12 years ago
JSP

Hello, a have a problem calling a servlet from JSP.. here's my code

I'm calling a servlet name SvPHeader and I'm getting an error HTTP Status 404 - /SvPHeader when clicking "Edit" . Thanks in advance for your assistance

<TR>
<TD><%=rs.getString(1)%></TD>
<TD><%=rs.getString(2)%></TD>
<TD><%=rs.getString(3)%></TD>
<TD><%=rs.getString(4)%></TD>
<td><a href="http://localhost:8081/SvPHeader?pono=<%=rs.getString(2)%>" />Edit</td>

</TR>
12 years ago
JSP

Bear Bibeault wrote:Submitting to a JSP is a very poor practice.

You might find this article helpful.



Thanks. That's the kind if confirmation I want to know from the expert.

Regards,
Danny
12 years ago
JSP

If you're coming from JSP with data to edit in a table, which is the best practice to do :

1. Use a servlet to "Set"(using bean) data and open another JSP to display data (using Bean) for editing
2. From JSP send parameter to another JSP and display data for editing.

The reason I ask this question is to know the best practive for MVC.

Thanks in advance for your help.
12 years ago
JSP

Jeanne Boyarsky wrote:Danny,
Welcome to CodeRanch!

What yo posted is the correct way of sending a parameter. Note that it is good practice to keep code (especially JDBC code) out of the JSP. Instead store it in the request attribute and read that in the JSP. Search MVC for more detail.



Thanks Jeanne. I was able to solve the problem above. I'm just newbie in Java/Jsp tech but already practicing MVC at this stage.

Hope this site and people like you will help me in my learning journey in this technology.

Thank you once again.
Danny

12 years ago
JSP
<TR>
<TD><%=rs.getString(1)%></TD>
<TD><%=rs.getString(2)%></TD>
<TD><%=rs.getString(3)%></TD>
<TD><%=rs.getString(4)%></TD>
<TD><input type="button" value="Edit" onclick=""/></TD>
<td><a href="EditPo.jsp?id=%=rs.getString("2")"%>Edit</a></td>

</TR>

please assist. THanks
12 years ago
JSP