No me puedo conectar a una bd
me conecto a una bd de la siguiente manera:
<%!
public class Conexion {
public Connection conexion() {
String url = "jdbc:postgresql://localhost:5432/dental";
String login = "alvaro";
String pass = "";
Connection connec = null;
try {
//Cargo el driver
Class.forName("org.postgresql.Driver");
}catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
//Establezco la conexión
connec = DriverManager.getConnection(url, login, pass);
return connec;
}catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
System.out.println("No conectado");
return connec;
}
}
}
%>
<% Conexion conex = new Conexion();
Connection miConnec = conex.conexion();
if (!miConnec.isClosed()) {
out.print("FUNCIONA !");
miConnec.close();
}else{
out.print("NO FUNCIONA !");
}
%>
Pero me sale este error:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:297)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:247)
javax.servlet.http.HttpServlet.service(HttpServlet .java:860)
sun.reflect.GeneratedMethodAccessor71.invoke(Unkno wn Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:324)
org.apache.catalina.security.SecurityUtil$1.run(Se curityUtil.java:249)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject .java:500)
org.apache.catalina.security.SecurityUtil.execute( SecurityUtil.java:282)
org.apache.catalina.security.SecurityUtil.doAsPriv ilege(SecurityUtil.java:165)
root cause
java.lang.NullPointerException
org.apache.jsp.control_jsp._jspService(control_jsp .java:96)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:105)
javax.servlet.http.HttpServlet.service(HttpServlet .java:860)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:336)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:297)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:247)
javax.servlet.http.HttpServlet.service(HttpServlet .java:860)
sun.reflect.GeneratedMethodAccessor71.invoke(Unkno wn Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:324)
org.apache.catalina.security.SecurityUtil$1.run(Se curityUtil.java:249)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject .java:500)
org.apache.catalina.security.SecurityUtil.execute( SecurityUtil.java:282)
org.apache.catalina.security.SecurityUtil.doAsPriv ilege(SecurityUtil.java:165)
note The full stack trace of the root cause is available in the Sun-Java-System/Application-Server logs.
la conexion funciona cuando lo hago mediante el shell de windows, pero en jsp no.
<%!
public class Conexion {
public Connection conexion() {
String url = "jdbc:postgresql://localhost:5432/dental";
String login = "alvaro";
String pass = "";
Connection connec = null;
try {
//Cargo el driver
Class.forName("org.postgresql.Driver");
}catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
//Establezco la conexión
connec = DriverManager.getConnection(url, login, pass);
return connec;
}catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
System.out.println("No conectado");
return connec;
}
}
}
%>
<% Conexion conex = new Conexion();
Connection miConnec = conex.conexion();
if (!miConnec.isClosed()) {
out.print("FUNCIONA !");
miConnec.close();
}else{
out.print("NO FUNCIONA !");
}
%>
Pero me sale este error:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:297)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:247)
javax.servlet.http.HttpServlet.service(HttpServlet .java:860)
sun.reflect.GeneratedMethodAccessor71.invoke(Unkno wn Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:324)
org.apache.catalina.security.SecurityUtil$1.run(Se curityUtil.java:249)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject .java:500)
org.apache.catalina.security.SecurityUtil.execute( SecurityUtil.java:282)
org.apache.catalina.security.SecurityUtil.doAsPriv ilege(SecurityUtil.java:165)
root cause
java.lang.NullPointerException
org.apache.jsp.control_jsp._jspService(control_jsp .java:96)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:105)
javax.servlet.http.HttpServlet.service(HttpServlet .java:860)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:336)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:297)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:247)
javax.servlet.http.HttpServlet.service(HttpServlet .java:860)
sun.reflect.GeneratedMethodAccessor71.invoke(Unkno wn Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:324)
org.apache.catalina.security.SecurityUtil$1.run(Se curityUtil.java:249)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject .java:500)
org.apache.catalina.security.SecurityUtil.execute( SecurityUtil.java:282)
org.apache.catalina.security.SecurityUtil.doAsPriv ilege(SecurityUtil.java:165)
note The full stack trace of the root cause is available in the Sun-Java-System/Application-Server logs.
la conexion funciona cuando lo hago mediante el shell de windows, pero en jsp no.
has declarado las librerias que necesitas en el encabezado?
Es decir, si has puesto los import en el jsp de la forma:
<%@ page import='javax.servlet.*' %>
Asà todas las que necesitas para las librerias de la base de datos y todo lo que uses
___________________________________
http:\usuarios.lycos.esehlcvesganadinero
Es decir, si has puesto los import en el jsp de la forma:
<%@ page import='javax.servlet.*' %>
Asà todas las que necesitas para las librerias de la base de datos y todo lo que uses
___________________________________
http:\usuarios.lycos.esehlcvesganadinero
