Results 1 to 2 of 2
- 07-05-2007, 05:28 AM #1
Senior Member
- Join Date
- Jun 2007
- Posts
- 111
- Rep Power
- 0
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
Java 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) %> <%= 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) %> <%= 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>Thank youJava 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>
Eric
- 07-05-2007, 05:31 AM #2
Member
- Join Date
- Jun 2007
- Posts
- 91
- Rep Power
- 0
Similar Threads
-
java.lang.OutOfMemoryError: Java heap space
By paul in forum Advanced JavaReplies: 11Last Post: 06-12-2010, 05:30 PM -
java.lang.UnsatisfiedLinkError: no parport in java.library.path
By Heather in forum NetBeansReplies: 3Last Post: 09-07-2009, 01:28 PM -
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String)
By baltimore in forum New To JavaReplies: 2Last Post: 09-18-2008, 07:30 AM -
java.lang.NumberFormatException: For input stream:jav
By osval in forum New To JavaReplies: 2Last Post: 08-07-2007, 03:50 PM -
Error: NumberFormatException
By coco in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:41 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks