Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-05-2007, 06:28 AM
Senior Member
 
Join Date: Jun 2007
Posts: 111
Eric is on a distinguished road
java.lang.NumberFormatException: null
Hi, the problem i thing is in the friendsmem variable..
but as you can see, i can get the friendsmem value and display it in the friends.jsp. I can even plus one to the friendsmem value, and it adds up correctly.
It give me the error after i click the button Update, as it inserts the value into the database.

search.jsp called friends.jsp. Im using a netbeans IDE 5.5 with bundled tomcat 5.5.17
Code:
<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <%@page import="java.sql.*" %> <%-- The taglib directive below imports the JSTL library. If you uncomment it, you must also add the JSTL library to the project. The Add Library... action on Libraries node in Projects view can be used to add the JSTL 1.1 library. --%> <%-- <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> --%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/> <meta name="description" content="description"/> <meta name="keywords" content="keywords"/> <meta name="author" content="author"/> <link rel="stylesheet" type="text/css" href="default.css" media="screen"/> <title>Slapped</title> </head> <body> <% Object mem = session.getValue("memberId"); String email = request.getParameter("email"); try { Class.forName("com.mysql.jdbc.Driver").newInstance(); String dbUrl = "jdbc:mysql:///jsp"; String dbUser = ""; String dbPassword = ""; Connection connection = DriverManager.getConnection(dbUrl, dbUser, dbPassword); DatabaseMetaData dbMetaData = connection.getMetaData(); Statement statement = connection.createStatement(); String query = "select count(*) from member where email = '"+email+"';"; String query1 = "select * from member where email = '"+email+"';"; ResultSet rs = statement.executeQuery(query); rs.next(); //if (rs.getInt(1) > 0){ %> <div class="container"> <div class="main"> <div class="header"> <div class="title"> <h1>User Page</h1> </div> </div> <div class="topmenu"> <a href="profile.jsp">View Profile</a> <a href="">Find Friends</a> <a href="">Groups</a> <a href="">Logout</a> </div> <br><br><br> <h1>User Name</h1> <br><br> <form action="search.jsp" method="get"> <h2>by email</h2><br> <input type="text" name="email" cols="40" row="6"> <input type="submit" value="Search"> </form> <% if(rs.getInt(1) > 0) { //int count = rs.getInt(1); rs = statement.executeQuery(query1); ResultSetMetaData rm = rs.getMetaData(); int columnCount = rm.getColumnCount(); //int id; //String fname = null; //String lname = null; /*while(rs.next()){ id = rs.getInt(1); fname = rs.getString(2); lname = rs.getString(3);*/ %> <form action="friends.jsp" method=post> <table border="1"> <h2><center>Results</center></h2><br> <th><h2>Name</h2></th> <% while(rs.next()){ %> <tr> <%--<td><h3><%= rs.getInt(1) %></h3></td><td><h3><%= rs.getString(2) %> &nbsp; <%= rs.getString(3) %></h3></td><td><input type="submit" value="Add to Friend"></td> --%> <input type=hidden name=friendsid value=<%= rs.getInt(1) %>><td><h3><%= rs.getString(2) %> &nbsp; <%= rs.getString(3) %></h3></td><td><input type="submit" value="Add to Friend"></td> </tr> </table> </form> <% }} %> </div> </div> <% if(rs != null) rs.close(); if(statement != null) statement.close(); if(connection != null) connection.close(); } catch (SQLException ex) { out.println(ex); } catch (IllegalAccessException ex) { out.println(ex); } catch (ClassNotFoundException ex) { out.println(ex); } catch (InstantiationException ex) { out.println(ex); } %> </body> </html>
Code:
<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <%@page import="java.sql.*" %> <%@page import="java.lang.*" %> <%@page import="java.util.*" %> <%-- The taglib directive below imports the JSTL library. If you uncomment it, you must also add the JSTL library to the project. The Add Library... action on Libraries node in Projects view can be used to add the JSTL 1.1 library. --%> <%-- <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> --%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/> <meta name="description" content="description"/> <meta name="keywords" content="keywords"/> <meta name="author" content="author"/> <link rel="stylesheet" type="text/css" href="default.css" media="screen"/> <title>Slapped</title> </head> <body> <% Object mem = session.getValue("memberId"); String friendsID = request.getParameter("friendsid"); String relationship = request.getParameter("relationship"); String description = request.getParameter("describerelationship"); int friendsmem = 0; PreparedStatement ps = null; Statement statement = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); String dbUrl = "jdbc:mysql:///JSP"; String dbUser = ""; String dbPassword = ""; Connection connection = DriverManager.getConnection(dbUrl, dbUser, dbPassword); boolean proceed = false; friendsmem = Integer.parseInt(friendsID); if(relationship != null && description != null) if(relationship.length() > 0 && description.length() > 0) proceed = true; String query = "insert into friends values ("+mem+",?,?,?);"; ps = connection.prepareStatement(query); statement = connection.createStatement(); if(proceed){ ps.setInt(1, friendsmem); ps.setString(2, relationship); ps.setString(3, description); ps.executeUpdate(); } %> <div class="container"> <div class="main"> <div class="header"> <div class="title"> <h1>User Page</h1> </div> </div> <div class="topmenu"> <a href="profile.jsp">View Profile</a> <a href="">Find Friends</a> <a href="">Groups</a> <a href="">Logout</a> </div> <br><br><br> <h1>User Name</h1> <h2><%= friendsmem %></h2> <br> <% if(proceed){%> <h3>Update Succeed</h3> <% } %> <br> <br> <form action="friends.jsp" method=post> <h2>What is your relationship:</h2><br> <textarea name=relationship cols=40 row=6></textarea> <h2>Describe your relationship:</h2><br> <textarea name=describerelationship cols=40 row=6></textarea><br> <input type=submit value=Update> </form> </div> </div> <% if(ps != null) ps.close(); if(statement != null) statement.close(); if(connection != null) connection.close(); } catch (SQLException ex) { out.println(ex); } catch (IllegalAccessException ex) { out.println(ex); } catch (ClassNotFoundException ex) { out.println(ex); } catch (InstantiationException ex) { out.println(ex); } catch (Exception ex) { out.println(ex); } %> </body> </html>
Thank you
Eric
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-05-2007, 06:31 AM
Member
 
Join Date: Jun 2007
Posts: 92
Daniel is on a distinguished road
Print the updatequery to your page, then you can see what you send to the database.

Greetings
Daniel
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
java.lang.NumberFormatException: For input stream:jav osval New To Java 2 08-07-2007 04:50 PM
Error: NumberFormatException coco New To Java 1 08-07-2007 08:41 AM
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String) baltimore New To Java 1 08-06-2007 08:45 AM
java.lang.OutOfMemoryError: Java heap space paul Advanced Java 1 07-25-2007 09:07 PM
java.lang.UnsatisfiedLinkError: no parport in java.library.path Heather NetBeans 2 06-29-2007 03:45 PM


All times are GMT +3. The time now is 07:34 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org