wood burning stoves 2.0*
The moose likes JDBC and the fly likes connectivity with remote mysql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "connectivity with remote mysql" Watch "connectivity with remote mysql" New topic
Author

connectivity with remote mysql

Deepak Rajkiran
Greenhorn

Joined: Feb 10, 2008
Posts: 6
I am trying to run jsp page on remote server (Linux) and doing connectivity with mysql.



<%!
Connection conn=null;
PreparedStatement pst=null;
ResultSet rs=null;

%>


<%
try
{


Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost/databasename?user=<username>&password=<password>");
System.out.println("driver connected");
}
catch(Exception ex)
{

System.out.println(ex);
}

%>

<%
String sql2="SELECT * FROM TABLENAME";
PreparedStatement pst=conn.prepareStatement(sql2);
rs=pst.executeQuery();

if(rs.next())
{
fname=rs.getString(3);
lname=rs.getString(4);
}




%>




I found exception in jsp page when connecting with jdbc...

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

exception

org.apache.jasper.JasperException: Exception in JSP: /UserData.jsp:37

34:
35: <%
36: String sql2="SELECT * FROM USERINFO";
37: PreparedStatement pst=conn.prepareStatement(sql2);
38: rs=pst.executeQuery();
39:
40: if(rs.next())


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.UserData_jsp._jspService(UserData_jsp.java:82)
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.25 logs.
[ April 25, 2008: Message edited by: Deepak Rajkiran ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41146
    
  45
The Connection object is assigned to "conn", while the NPE happens for "connection".


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: connectivity with remote mysql
 
Similar Threads
Module 'null' not found struts1.3.8+spring2.0
Axis2 - WSDL to code
Using SQL statements in JSP
Web App cannot see Mysql data
getting Exception in JSP