•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 456,472 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 2,795 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
Views: 1244 | Replies: 3
![]() |
•
•
Join Date: Sep 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
I get the following when attempting to view a project I have, I have MySQL 5.0 and Tomcat 6.0. Both services are running. As far as MySQL connectors, I have both "mysql-connector-java-5.0.7-bin" and "mysql-connector-java-3.0.8-stable-bin". This has not worked with either one.
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /test.jsp at line 8
5: </head><body>
6: <%
7: DBConnect d = new DBConnect();
8: ResultSet rs = d.getResult("SELECT * FROM items");
9: //this is where you loop over your results
10:
11: while (rs.next()) {
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NullPointerException
com.monkeygarage.DBConnect.getResult(Unknown Source)
org.apache.jsp.test_jsp._jspService(test_jsp.java:62)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.
Apache Tomcat/6.0.14
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /test.jsp at line 8
5: </head><body>
6: <%
7: DBConnect d = new DBConnect();
8: ResultSet rs = d.getResult("SELECT * FROM items");
9: //this is where you loop over your results
10:
11: while (rs.next()) {
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NullPointerException
com.monkeygarage.DBConnect.getResult(Unknown Source)
org.apache.jsp.test_jsp._jspService(test_jsp.java:62)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.
Apache Tomcat/6.0.14
•
•
Join Date: Sep 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
and here is my code to connect to the DB, minus correct login info:
package com.monkeygarage;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBConnect {
private Connection conn;
private String db = "";
private String host = "l";
private String pass = "";
private Statement statement;
private String user = "";
/**
*
*/
public DBConnect() {
connect();
}
private void connect() {
try {
Class.forName("com.mysql.jdbc.Driver");
// create connection string
String connUrl = "jdbc:mysql://" + this.host + "/" + this.db + "?user="
+ this.user + "&password=" + this.pass;
// pass database parameters to JDBC driver
this.conn = DriverManager.getConnection(connUrl);
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public void disconnect() {
try {
this.statement.close();
this.conn.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public ResultSet getResult(String sql) throws SQLException {
if (this.statement != null) {
this.statement.close();
}
this.statement = this.conn.prepareStatement(sql);
this.statement.setMaxRows(1);
return this.statement.executeQuery(sql);
}
public static void main(String[] args) {
try {
DBConnect d = new DBConnect();
ResultSet rs = d.getResult("SELECT * FROM items");
while (rs.next()) {
String name = rs.getString("name");
System.out.println(name);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
•
•
Join Date: May 2008
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
In the following examples, please substitute your information where the following data is referenced:
<server>: enter the MySQL server that you are assigned to, for example, mysql4.safesecureweb.com
<username>: enter the username provided for your database
<password>: enter the password provided for your database
<database>: enter the database name provided for your database
<DSN>: enter the DSN name (ColdFusion only)
PHP
<?php
$link = mysql_connect('<server>', '<username>', '<password>');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db(<database>);
?>
ColdFusion
<CFQUERY Name="test" DATASOURCE="<DSN>" USERNAME="<username>" PASSWORD="<password>">
</CFQUERY>
Perl
#!/usr/bin/perl
use DBI;
$db = DBI->connect("dbi:mysql:<database>","<username>","<password>")
or die("Couldn't connect");
$db->disconnect;
JSP
<%@ page import="java.sql.*" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%!
Class.forName("com.mysql.jdbc.Driver").newInstance();
java.sql.Connection conn;
conn = DriverManager.getConnection(
"jdbc:mysql://<server>/<database>?user=<username>&password=<password>");
%>
<server>: enter the MySQL server that you are assigned to, for example, mysql4.safesecureweb.com
<username>: enter the username provided for your database
<password>: enter the password provided for your database
<database>: enter the database name provided for your database
<DSN>: enter the DSN name (ColdFusion only)
PHP
<?php
$link = mysql_connect('<server>', '<username>', '<password>');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db(<database>);
?>
ColdFusion
<CFQUERY Name="test" DATASOURCE="<DSN>" USERNAME="<username>" PASSWORD="<password>">
</CFQUERY>
Perl
#!/usr/bin/perl
use DBI;
$db = DBI->connect("dbi:mysql:<database>","<username>","<password>")
or die("Couldn't connect");
$db->disconnect;
JSP
<%@ page import="java.sql.*" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%!
Class.forName("com.mysql.jdbc.Driver").newInstance();
java.sql.Connection conn;
conn = DriverManager.getConnection(
"jdbc:mysql://<server>/<database>?user=<username>&password=<password>");
%>
![]() |
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- error in connecting MySql and PHPBB help me..... (MySQL)
- Help connecting to mysql tables (JSP)
- connecting to mysql in linux (Java)
- php mysql help (PHP)
- Can't connect error on createuser (PHP)
- help with mysql_connect(); (PHP)
- Connecting to MySQL (MySQL)
- Connecting via Winmatrix to Access (ASP.NET)
Other Threads in the JSP Forum
- Previous Thread: JSF hibernateUtl
- Next Thread: code question


Linear Mode