Welcome to Dream.In.Code
Become a Java Expert!

Join 150,381 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,229 people online right now. Registration is fast and FREE... Join Now!




jsp

 
Reply to this topicStart new topic

jsp, unable to throw a correct exception

ganesh251284
4 Feb, 2008 - 04:00 AM
Post #1

New D.I.C Head
*

Joined: 30 Jan, 2008
Posts: 7

below is my jsp code from html it is taking any csv ox xls file ,if in that xls file float having string ,then it must throw number format exception,but it is showing null pointer exception
CODE

<%@ page contentType="text/html;charset=windows-1252"%>
<%@ page import ="java.sql.*" %>
<%@ page import ="java.io.*" %>
<%@ page import ="java.net.*" %>
<%@ page import ="java.util.*" %>
<%@page pageEncoding="UTF-8"%>
<%@ page import ="javax.naming.InitialContext" %>
<%@ page import ="java.sql.PreparedStatement.*" %>
<%@ page import ="java.lang.*" %>


<html>
<head><head>
<body>
<form name="upload" method="get">
<%
try {
String up2=request.getParameter("up1");


String InputFileName =up2;
File file1= new File(InputFileName);

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String s19 = "Driver={Microsoft Excel Driver (*.xls)};DBQ=" + file1+ ";READONLY=false;";
Connection conn = DriverManager.getConnection("jdbc:odbc:" + s19, "", "");
System.out.println("Connection made successfully to the excel sheet");
DatabaseMetaData databasemetadata = conn.getMetaData();

Statement statement1 = conn.createStatement();
ResultSet resultset2 = databasemetadata.getTables(null, null, null, null);
Vector vector = new Vector();
for(; resultset2.next(); vector.add(resultset2.getString(3)));
resultset2.close();

Statement st = conn.createStatement();
ResultSet rs = st.executeQuery( "Select * from ["+vector.get(0)+"]" );
while (rs.next()) {

try {
String SYMBOL=rs.getString(1);
float OPEN=Float.parseFloat(rs.getString(2));
float HIGH=Float.parseFloat(rs.getString(3));
float LOW=Float.parseFloat(rs.getString(4));
float CLOSE=Float.parseFloat(rs.getString(5));
float LAST=Float.parseFloat(rs.getString(6));
float PREVCLOSE=Float.parseFloat(rs.getString(7));
float TOTTRDQTY=Float.parseFloat(rs.getString(8));
float TOTTRDVAL=Float.parseFloat(rs.getString(9));
String TIMESTAMP=rs.getDate(10).toString();
if(OPEN==0.0 || HIGH==0.0 || LOW==0.0 || CLOSE==0.0|| LAST==0.0 ||PREVCLOSE==0.0||TOTTRDQTY==0.0||TOTTRDVAL==0.0 ){
throw new Exception("it should not be equal to 0");
}
boolean flag=false;
try{
Class.forName("com.ashna.jturbo.driver.Driver");
Connection con;
con=DriverManager.getConnection("jdbc:JTurbo://10.1.33.20:1433/ganesh","estar","eagle");
Statement st1=con.createStatement();
ResultSet result=st1.executeQuery("SELECT TSYMBOL,TOPENS,THIGH,TLOWS,TCLOSES,TLASTS,TPREVCLOSE,TTOTTRDQTY,TTOTTRDVAL,TTIME

STAMP FROM NSE2");
if(result.next())
{
do {
String SYMBOL1=result.getString("TSYMBOL");
float OPENS1=result.getFloat("TOPENS");
float HIGH1=result.getFloat("THIGH");
float LOWS1=result.getFloat("TLOWS");
float CLOSES1=result.getFloat("TCLOSES");
float LASTS1=result.getFloat("TLASTS");
float PREVCLOSE1=result.getFloat("TPREVCLOSE");
float TOTTRDQTY1=result.getFloat("TTOTTRDQTY");
float TOTTRDVAL1=result.getFloat("TTOTTRDVAL");
String TIMESTAMP1=result.getDate("TTIMESTAMP").toString();
//out.write("get" + SYMBOL1);
if (SYMBOL1.equals(SYMBOL) && TIMESTAMP1.equals(TIMESTAMP))
{
flag=true;
break;
}

}while(result.next());
}

if(flag==true)
{
st1.executeUpdate("UPDATE NSE2 SET TOPENS="+OPEN+",THIGH="+HIGH+",TLOWS="+LOW+",TCLOSES="+CLOSE+",TLASTS="+LAST+",TPREVCLOSE="+PREVCLOSE+",TTOTTRDQTY="+TOTTRDQTY+",TTOTTRDVAL="+TOTTRDVAL+" WHERE TSYMBOL='"+SYMBOL+"' AND TTIMESTAMP='"+TIMESTAMP+"' ");
}
else {
st1.executeUpdate("INSERT INTO NSE2 VALUES('"+SYMBOL+"',"+OPEN+", "+HIGH+","+LOW+", "+CLOSE+","+LAST+","+PREVCLOSE+","+TOTTRDQTY+","+TOTTRDVAL+",'"+TIMESTAMP+"')");
}
}

catch(SQLException e)
{
out.write(e.getMessage());
}
}

catch(Exception e2){
out.write("Error"+e2);
out.write(" \n");
}
}
rs.close();
st.close();
conn.close();
%>

<center> <h3> data is inserted </h3> </center>
<%
}
catch(Exception e){
out.write(e.getMessage());
%>
<center><h3>DATA is not INSERTED</h3></center>
<% }
%>
</form>
</body>
</html>

User is offlineProfile CardPM
+Quote Post

1lacca
RE: Jsp
4 Feb, 2008 - 04:14 AM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
1) Please don't start multiple topics with the same question.
2) Please use code tags to post your code code.gif
3) Please post the exception with stack trace included.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 04:07PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month