User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 373,932 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,212 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting

How to Connect MySQL from JSP Page

Join Date: Jan 2008
Posts: 32
Reputation: electron33 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 4
electron33 electron33 is offline Offline
Light Poster

Re: How to Connect MySQL from JSP Page

  #16  
Feb 5th, 2008
Don't mix Servlet and JSP. Add the following code into a JSP page. Don't put it inside a function. JSP pages don't use function. Servlets do.

By the way. Database connections and business logic does not belong in the JSP pages. Move them down to Servlet or other specialized classes for the task.

<html>
<head>
    <title></title>
</head>
<body>
    
   <% 
        try{
            java.sql.Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:8009/test", "root", "asma");
            java.sql.PreparedStatement stmt = conn.prepareStatement("SELECT * FROM test");
            ResultSet rs = stmt.executeQuery();
            while(rs.next()){

            }
        }
        catch(Exception e){
            e.printStackTrace();
        }
   %>
</body>
</html>
Reply With Quote  
All times are GMT -4. The time now is 6:13 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC