hello i have a simple problem in jsp in the sense to get data from the database like oracle . I have created one jsp program like this
<@ page session="false"%> <@ page import="java.io.*" import="java.sql."%> <%try { PreparedStatement ps; Connectin con; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DrivergetConnection("jdbc:odbc:DNSName","scott","tiger"; ps=con.prepareStatement(); ResultSet rs=ps.executeQuery("select from Table1"); if(rs.next()) { out.println(rs.getInt(1)); out.println(rs.getString(2)); out.println(rs.getString(3)); out.println(rs.getInt(4)); } } catch(Exception e) {} rs.close(); ps.close(); con.close(); %>
But now when i iam saving this program in JSP it is alright , when i opened the Tomcat and getting the necessary path then i clicked on the JSP file i,but i am not getting any thing in the internet Browser.i have given the data (Table1) in the database.so that data should come on the Browser. but not getting.So kindly the RoseIndia netizens help to solve the problem
Use the following code:
ResultSet rs=ps.executeQuery("select * from Table1"); while(rs.next()) { out.println(rs.getInt(1)); out.println(rs.getString(2)); out.println(rs.getString(3)); out.println(rs.getInt(4)); }
Hi my friend roseinsia netizen has given me to execute the program by while instead of if but neither while nor if statements iam not getting the solution .Exactly what i have done is that ( i have a simple problem in jsp in the sense to get data from the database like oracle), I have created one jsp program like this
*<@ page session="false"%> <@ page import="java.io." import="java.sql."%> <%try { PreparedStatement ps; Connectin con; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DrivergetConnection("jdbc:odbc:DNSName","scott","tiger"; ps=con.prepareStatement(); ResultSet rs=ps.executeQuery("select from Table1"); while(rs.next()) { out.println(rs.getInt(1)); out.println(rs.getString(2)); out.println(rs.getString(3)); out.println(rs.getInt(4)); } } catch(Exception e) {} rs.close(); ps.close(); con.close(); %>**
But now when i iam saving this program in JSP it is alright , when i opened the Tomcat and getting the necessary path then i clicked on the JSP file but i am not getting any thing in the internet Browser.i have given the data (Table1) in the database.so that data should come on the Browser. but not getting.So kindly the RoseIndia netizens help to solve the problem.
You have used incorrect query. Actually you didn't clear which data you want to retrieve. Neither you have used * nor you have specifies particular field.So if you want to retrieve all the fields then use this code:
ResultSet rs=ps.executeQuery("select * from Table1"); while(rs.next()) { out.println(rs.getInt(1)); out.println(rs.getString(2)); out.println(rs.getString(3)); out.println(rs.getInt(4)); }
And if you want to retrieve the particular data then use this code:
ResultSet rs=ps.executeQuery("select * from Table1 where id=1"); if(rs.next()) { out.println(rs.getInt(1)); out.println(rs.getString(2)); out.println(rs.getString(3)); out.println(rs.getInt(4)); }
hello My Netizen friend has given the answer to retrieve data from the database by using servlet or jsp program by typing the output as like this below
ReusltSet rs=statement.executeQuery("select * from Table1) while(rs.next()) { out.println(rs.getInt(1)); out.println(rs.getString(2)); out.println(rs.getString(3)); out.println(rs.getInt(4)); }
But still i am not gettin the output from the Browser. i have a simple problem in jsp in the sense to get data from the database like oracle . I have created one jsp program like this
<@ page session="false"%> <@ page import="java.io.*" import="java.sql."%> <%try { PreparedStatement ps; Connectin con; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DrivergetConnection("jdbc:odbc:DNSName","scott","tiger"; ps=con.prepareStatement(); ResultSet rs=ps.executeQuery("select from Table1"); if(rs.next()) { out.println(rs.getInt(1)); out.println(rs.getString(2)); out.println(rs.getString(3)); out.println(rs.getInt(4)); } } c atch(Exception e) {} rs.close(); ps.close(); con.close(); %>
But now when i iam saving this program in JSP it is alright , when i opened the Tomcat and getting the necessary path then i clicked on the JSP file i,but i am not getting any thing in the internet Browser.i have given the data (Table1) in the database.so that data should come on the Browser. but not getting.So kindly the RoseIndia netizens help to solve the problem
<@ page session="false"%> <@ page import="java.io.*" import="java.sql.*"%> <%try { PreparedStatement ps=null; Connectin con=null; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:DNSName","scott","tiger"); ps=con.prepareStatement("select * from Table1"); ResultSet rs=ps.executeQuery(); while(rs.next()) { out.println(rs.getInt(1)); out.println(rs.getString(2)); out.println(rs.getString(3)); out.println(rs.getInt(4)); } } catch(Exception e) {} rs.close(); ps.close(); con.close(); %>
ResultSet rs=ps.executeQuery("**select from Table1**"); **Incorrect statement:** select from Table1 **Correct statement:** select * from Table1 **Write code:** ResultSet rs=ps.executeQuery("**select * from Table1**"); It's really work ......