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:

<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>

Here's the error I keep getting:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Exception in JSP: /x/BMI2.jsp:48

45:         }
46: 
47: %>
48:  <%= myData.getString(1) %> 
49:  <%= myData.getString(2) %> 
50:  <%= myData.getString(3) %> 
51:  


Stacktrace:
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

java.lang.NullPointerException
	org.apache.jsp.x.BMI2_jsp._jspService(BMI2_jsp.java:99)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.26 logs.

Please don't tell me to search google for this problem because I have spent countless hours trying to solve this and I'm going insane! :'(

please help!

no, we don't help little whining kids who insist on doing bad things like putting Java code inside JSP.
If you want to access a database, use a servlet.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.