Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: What is wrong in the code

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What is wrong in the code

    Data not getting retrieved from database table with below code , What going wrong pls advise.........
    HTML Code:
    <%@ page language="java" import="java.sql.*;"%>
    <html>
    <head>
    <style>
    A:hover {
    
    text-decoration: none;
    font-family:arial;
    font-size:12px;
    color: #000000;
    BORDER: none;
    }
    A {
    
    text-decoration: underline;
    font-family:arial;
    font-size:12px;
    color: #000000;
    BORDER: none;
    
    }
    
    </style>
    </head>
    <body>
    <br><br><br>
    <%
    
            Connection conn = null;
    		String url = "jdbc:mysql://localhost:3306/";
    		String dbName = "bank";
    		String driver = "com.mysql.jdbc.Driver";
    		String username = "root";
    		String userPassword = "java";
    		String color = "#F9EBB3";
            
    		String date = request.getParameter("value");
    		
    		try {
    			Class.forName(driver).newInstance();
    			conn = DriverManager.getConnection(url + dbName, username,
    					userPassword);
    
    			Statement st = conn.createStatement();
    			String strQuery = "select * from  transaction"; 
    			ResultSet rs = st.executeQuery(strQuery);
    			
    			
    			
    %>  
    
    <table width="600px" align="center"  style="border:1px solid #000000;" >
    
    <tr><td><b>Transaction ID :</b></td><td><%=rs.getInt("transactionId")%></td></tr>
    <tr><td><b>Acc No. :</b></td><td><%=rs.getInt("accountNo")%></td></tr>
    <tr><td><b>Additional Information :</b></td><td><%=rs.getString("addInfo")%></td></tr>
    </table>
    <br><br><br>
    <table width="600px" align="center" >
    <tr><td align="center"><input type="submit" name="Submit" value="Save As Draft"></td>
    <td align="center"><input type="submit" name="Submit" value="Sent TO RBI"></td>
    <td align="center"><input type="submit" name="Submit" value="PRINT"></td></tr>
    
    <%	 		
    	 		System.out.println("Connected to the database");
     			conn.close();
     			System.out.println("Disconnected from database");
     		} catch (Exception e) {
     			e.printStackTrace();
     		}
    %>		
    	
    </table>
    </body>
    </html>


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: What is wrong in the code

    Are you certain that the code is allowing you to connect to the database correctly? Obviously we have no way of testing this.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What is wrong in the code

    Yes dude , Code allowing me connect to database but database values not getting displayed??????????

  4. #4
    Junior Member
    Join Date
    Jul 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What is wrong in the code

    awaiting for reply.................

  5. #5
    Junior Member
    Join Date
    Jun 2011
    Posts
    26
    My Mood
    Fine
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: What is wrong in the code

    Try

    String strQuery = "select * from transaction;";

    instead of

    String strQuery = "select * from transaction";

    in the try block.

Similar Threads

  1. want wrong with my code
    By drum in forum Member Introductions
    Replies: 1
    Last Post: May 20th, 2011, 10:06 AM
  2. What is Wrong with my code
    By xew123 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 8th, 2011, 04:59 AM
  3. What's wrong with my code?
    By lindmando in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 7th, 2011, 11:13 PM
  4. what is wrong in this code
    By rk.kavuri in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 6th, 2011, 03:13 PM
  5. Wrong code
    By whattheeff in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 4th, 2011, 05:30 PM