Results 1 to 7 of 7
- 04-05-2010, 02:15 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 1
- Rep Power
- 0
JDBC SQL Service Error: java.lang.NullPointerException
Here is my code, what needs to change for this to work? I am using SQL 2008 and JDBC 2.0 drivers from Microsoft. when I run the stored procedure it pulls results just fine. (see code below for sp and jsp)
Stored Procedure code:
Create Table #Reservations (Checkin datetime not null,
checkout datetime not null)
Insert Into #Reservations (Checkin,Checkout)
select distinct checkin,checkout from bookings
Create Table #myTable ( ag_year int,
ag_month smallint,
ag_day varchar(10),
ag_message varchar(10),
ag_bgcolor varchar(10),
ag_action varchar(10),
ag_boxit varchar(10),
ag_fgcolor varchar(10),
ag_bgimg varchar(10),
ag_html varchar(10),
resid int )
Declare @Day int,@ID int ,@Start datetime ,@END datetime
DECLARE mydates CURSOR
READ_ONLY
FOR
Select Checkin,Checkout
FROM #Reservations
OPEN mydates
FETCH NEXT FROM mydates INTO @start,@end
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF (@@FETCH_STATUS <> -2)
BEGIN
Select @Day = 0
While dateadd(dd,@day,@start) <= @end
Begin
insert #myTable (ag_year, ag_month, ag_day, ag_message, ag_bgcolor,
ag_action, ag_boxit, ag_fgcolor, ag_bgimg, ag_html,resid)
Select year(dateadd(dd, @day, @start)),month(dateadd(dd, @day,@start)),
day(dateadd(dd, @day, @start)), 'Reserved', 'red', null, 'true', null, null,
null,@ID
Select @day = @day + 1
END
END
FETCH NEXT FROM mydates INTO @Start,@END
END
CLOSE mydates
DEALLOCATE mydates
select * from #myTable
drop table #Reservations
drop table #mytable;
----------------------------------------------------------------------------------------------------------
Web page (file.jsp) code:
<%@ page contentType="text/javascript" %>
<% // The above JSP code set the generated page to be recognized as a javascript source. %>
<% java.sql.Connection conn=null;
try {
// Establish database connection
javax.naming.Context ctx = new javax.naming.InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("jdbc/bookingsSQL");
conn = ds.getConnection();
// Execute SQL and get a result set
java.sql.CallableStatement cs = conn.prepareCall("{call BookingInput}");
cs.execute();
java.sql.ResultSet rs = cs.getResultSet();
while (rs.next())
//// Loop through the result set to generate multiple fAddEvent() functions
%>
fAddEvent(<%=rs.getString("ag_year")%>,<%=rs.getSt ring("ag_month")%>,<%=rs.getString("ag_day")%>,
'<%=rs.getString("ag_message")%>','<%=rs.getString ("ag_action")%>','<%=rs.getString("ag_bgcolor")%>' ,'<%=rs.getString("ag_fgcolor")%>','<%=rs.getStrin g("ag_bgimg")%>',<%=rs.getString("ag_boxit")%>,'<% =rs.getString("ag_html")%>');
<%
// Close db connection and error handling
rs.close();
cs.close();
} catch (Exception e) {
System.out.println("Service Error: "+e);
} finally {
if (conn!=null)
try { conn.close(); } catch (Exception ignore) {}
}
%>Last edited by scottbak; 04-05-2010 at 02:20 AM.
- 04-06-2010, 11:00 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Where do you get your NPE?
But I will say, take out all the code from this JSP and use a Servlet and a database access layer...it won't fix your problem, but it will be easier to debug and read.
- 04-06-2010, 11:54 AM #3
First of all ,You should not embed the Database code inside JSP.
next thing is you should not put empty catch block.Put printStackTrace to trace out the exeception.Ramya:cool:
- 04-12-2010, 03:45 PM #4
You are best to debug mode with a check again, should not transfer the parameter is correct
- 04-12-2010, 04:08 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 04-12-2010, 06:55 PM #6
Member
- Join Date
- Mar 2010
- Posts
- 5
- Rep Power
- 0
plz help....
im nt understanding What is wrong wid this code.....
its showing an error no data bt d database which m using z nt empty
Java Code:import java.sql.*; public class AuthorsInfo { public static void main(String args[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn =DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};Db=C:/Javajdk1.6.0_01/bin/Db.mdb;"); Statement stat = conn.createStatement(); ResultSet rs = stat.executeQuery("SELECT* FROM authors WHERE city='Dehradun'"); System.out.println("Authorid\tFirst NAme\t Last Name\t City"); while(rs.next()) { String id=rs.getString("au_id"); String lname=rs.getString("au_id"); String fname=rs.getString("au_fname"); String city=rs.getString("city"); if(fname.length()<=7) System.out.println(fname+"\t\t"); else System.out.println(fname+"\t"); if (lname.length()<=7) System.out.println(fname+"\t\t"); else System.out.println(fname+"\t"); System.out.println(city); } conn.close(); } catch (Exception ex) { System.out.println("Error occured"); System.out.println("Error:"+ex); } } }Last edited by Eranga; 04-12-2010 at 07:05 PM. Reason: code tags added
- 04-12-2010, 07:07 PM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
First of all, please do not post your questions on others threads, if your question is not relevant with the original. Please start a new thread in appropriate sub-forum next time.
And also please use code tags when you posting again.
Regarding your question, what happen? Did you comes with any errors?
Similar Threads
-
java.lang.NullPointerException Error
By Manfizy in forum NetBeansReplies: 3Last Post: 02-24-2011, 06:27 AM -
Please solve my error occured java.lang.NullPointerException
By Viruthagiri in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 03-24-2010, 12:08 PM -
Please solve my java.lang.NullPointerException error.?
By Viruthagiri in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 03-23-2010, 09:30 PM -
Thread: Error 500--Internal Server Error java.lang.NullPointerException
By jackdear44 in forum New To JavaReplies: 1Last Post: 12-05-2009, 07:28 AM -
Error Java.lang.NullPointerException in JBuilder2006
By Jack in forum Other IDEsReplies: 2Last Post: 07-02-2007, 02:29 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks