Skip to main content

No database??

3 replies [Last post]
cliveswan
Offline
Joined: 2009-11-30

Hi, trying to get simple sample database working.
Using NetBeans with GlassFish.

The browser fires, only get the database class??
No data, can anyone assist??

JSP output:
oracle.jdbc.driver.OracleDriver
NO error message

<%@ page import="java.sql.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%
Connection con = null;
Statement st;
ResultSet rs;
String sql = "";

String ProjectID = "";

sql = "SELECT * FROM Project";

try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin@localhost:1521:test","test","test");
st = con.createStatement();
rs = st.executeQuery(sql);
%>

<%
while(rs.next())
{
%>
<%=rs.getString("ProjectID")%>
<%=rs.getString("SubID")%>
<%=rs.getString("AsID")%>
<%=rs.getString("Name")%>

<% } %>

<%
rs.close();
con.close();
}

catch(Exception ex)
{
out.print(ex.getMessage());
}
%>

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cliveswan
Offline
Joined: 2009-11-30

Spent 2 days trying to sort this out. Bloody annoying!!

This was missing :
con = DriverManager.getConnection("jdbc:oracle:thin@localhost:1521:test","test","test");

Should be
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:test","test","test");

Jan Luehe

webtier@javadesktop.org wrote:
> Spent 2 days trying to sort this out. Bloody annoying!!
>
> This was missing :
> con = DriverManager.getConnection("jdbc:oracle:thin@localhost:1521:test","test","test");
>
> Should be
> DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:test","test","test");
>

Glad you were able to figure this out!
Was this a documentation bug?
If so, we'll fix it.
Please let us know.

Thanks,

Jan

> [Message sent by forum member 'cliveswan' (clive.swan@ntlworld.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=391258
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

cliveswan
Offline
Joined: 2009-11-30

I deleted the project, created a new project.

Now it has Error: Invalid Oracle URL specified

I have spent 2 days trying to get this working.
I would appreciate any assistance.

Services:
Database Driver: oracle.jdbc.driver.OracleDriver
Driver

<%@ page import="java.sql.*" %>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%--
Document : index
Created on : Mar 10, 2010, 4:26:09 PM
Author : Administrator
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>


<%
Connection con = null;
Statement st;
ResultSet rs;
String sql = "";

String ProjectID = "";
//ProjectID= Integer.parseInt(request.getParameter("ProjectID"));

//sql = "SELECT * FROM Project where ProjectID = "+ ProjectID;
sql = "SELECT * FROM Project";

try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin@localhost:1521:orcl","test","test");
st = con.createStatement();
rs = st.executeQuery(sql);
%>

<%
while(rs.next())
{
%>

<% } %>

<%=rs.getString("ProjID")%> <%=rs.getString("SubID")%> <%=rs.getString("AsID")%> <%=rs.getString("Name")%>

<%
rs.close();
con.close();
}

catch(Exception ex)
{
out.print(ex.getMessage());
}
%>