Problems connecting jsp with MySQL database

Discussion in 'JSP' started by genji, Apr 16, 2008.

  1. genji

    genji New Member

    Joined:
    Apr 16, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    hey guys

    I've been trying to connect this jsp site with MySQL database for a school assignment and I just can't seem to get it to work. It's getting really really frustrating because I have copied my friend's code(which does work on his pc) and for some odd reason it just won't work on my pc!(yes i changed the database names/passwords/table names in the code)

    I'm using Tomcat, MySQL front and MySQL server(same as my classmates).

    Here's the code:
    Code:
    <html>
    <head><title>Enter to database</title></head>
    <body>
    <table>
    <%@ page import="java.util.*" %>
    <%@ page import="javax.sql.*" %>
    <%@ page import="java.sql.*" %>
    <%@ page import = "java.awt.*" %>
    <%@ page import = "java.awt.event.*" %>
    <%@ page import = "java.util.*" %>
    <%@ page import = "javax.swing.*" %>
    
    <% 
        String queryString =null;
        PreparedStatement statement = null;
        Connection connection = null;
        ResultSet myData = null;
    	Object ophalen;
            try {
                
                
                Class.forName("com.mysql.jdbc.Driver");
                
                
                connection = DriverManager.getConnection
                        ("jdbc:mysql://localhost:3306/friends","root", "root");
                
                
                
                
                
                queryString = "SELECT * from tableoffriends" ;
                statement = connection.prepareStatement(queryString);
    
                myData = statement.executeQuery();
                
    			myData.next();
    
    			//zet alles in een variable en roep de variable onder op , stayli <%= variable
    
                    
    
            } 
    		catch(Exception SQLException) {
            }
    
    %>
     <%= myData.getString(1) %> 
     <%= myData.getString(2) %> 
     <%= myData.getString(3) %> 
     
    
    </body>
    </html>
    
    
     
  2. genji

    genji New Member

    Joined:
    Apr 16, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    please help!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice