| Author |
displaying data from mysql database.
|
Harshal Gurav
Ranch Hand
Joined: May 29, 2008
Posts: 150
|
|
Hi, In main.jsp i wish to display the data from the database( user information stored in user table ). my codein main.jsp is: <h2> description about user:</h2> <% Statement st = null; ResultSet rs = null; rs = st.executeQuery("Select description from user "); %> <option value = "<%=rs.getString("description")%>" > </option> when i run the above code it shows the error: java.lang.NullPointerException org.apache.jsp.main_jsp._jspService(main_jsp.java:72) like rs=st.execute.... can anybody have solution for above or any alternative code. Thanks and regards Harshal
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56202
|
|
You shouldn't be doing JDBC code in a JSP. That's a very bad practice. But how can you look at the following two lines of code: and not see how that will create a null pointer exception? I've moved this to the JDBC forum as it has nothing to do with JSP.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Jetendra Ivaturi
Ranch Hand
Joined: Feb 08, 2007
Posts: 159
|
|
As breat told we are not supposed to use Jdbc code in Jsp. If you would like to retrive the data from a table(irrespective or database). These things are manadatory. 1. Importing the package. import java.sql.*; 2. Loading the Driver Class.forName("the driver class which yu want to use"); 3. Connecting to database Connection con=DriverManager.getConnection(URL); 4. Creatign the statement(which you did not do) Statement st=con.createStatement(); 5. Query for trasactional query ResultSet ra=st.executeQuery("select.."); 6. Close the connection.
|
SCJP 1.4 & 1.5, SCWCD 1.5. Learn and Let Learn.
|
 |
 |
|
|
subject: displaying data from mysql database.
|
|
|