d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Help Please (sql Database To Jsp Page) > Paying Fg For Help!
123Next
Add Reply New Topic New Poll
Member
Posts: 2,780
Joined: Dec 22 2008
Gold: 3,743.00
Nov 16 2015 08:00pm
I have to create a page that displays some colunms from an SQL database and display it on a JSP page that I make on websphere. I am connected to the SQL server and the table name is dbo.Products. I've been working on this code for wayyyy too long and I know its something really simple. I now the basic Select * from (specific column) but that throws an exception. I'm stuck and need help!!!
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 16 2015 08:16pm
select * from table, not select * from column
Member
Posts: 2,780
Joined: Dec 22 2008
Gold: 3,743.00
Nov 16 2015 08:17pm
This is my code:

Use WAS8.x Web Server and the following JSP code to test to see if you can connect to the Northwind database using the above ODBC DSN:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<%@page
language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.*"%>
<html>
<head>
<title>Connect to Northwind_64 Bit SQL Server DSN</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<%
//setup url (bridge-driver name + ODBC DSN), user, and password Strings
String dsn = “Northwind_64”;
String dbUrl = "jdbc:odbc:" + dsn;
String user = "";
String password = "";
Connection connection = null;
try
{

// try to load the JDBC-ODBC driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
out.print("About to try to connect to ODBC DSN: " + dbUrl + "<br /><br />");
//try to connect to database using the above Strings
connection = DriverManager.getConnection(dbUrl, user, password);
out.print("Connected to ODBC DSN: " + dbUrl + "<br /><br />");
}
catch(Exception e)
{
out.print("Could Not Connect to ODBC DSN: " + dbUrl + "<br /><br />" + e.toString());
}
%>
</body>
</html>


And it says successfully connected...

But I need it to display some columns from The Northwind server and the name of the table is Products(dbo.Products)
I need to Display the ProductID, ProductName, and UnitPrice
Member
Posts: 2,780
Joined: Dec 22 2008
Gold: 3,743.00
Nov 16 2015 08:18pm
Quote (carteblanche @ Nov 17 2015 02:16am)
select * from table, not select * from column


Ive tried every way and it still throws an exception.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 16 2015 08:21pm
you posted your code to connect, but you didn't post your code to fetch the data. what is the exception?

This post was edited by carteblanche on Nov 16 2015 08:21pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 16 2015 08:36pm
just go ahead and query the data after you make the connection. post your jdbc call with your exception.
Member
Posts: 2,780
Joined: Dec 22 2008
Gold: 3,743.00
Nov 16 2015 08:48pm
Quote (carteblanche @ Nov 17 2015 02:36am)
just go ahead and query the data after you make the connection. post your jdbc call with your exception.


I'm not sure if this is even close but this is the code I had after:
// try to load the JDBC-ODBC driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
out.print("About to try to connect to ODBC DSN: " + dbUrl + "<br /><br />");
//try to connect to database using the above Strings
connection = DriverManager.getConnection(dbUrl, user, password);
out.print("Connected to ODBC DSN: " + dbUrl + "<br /><br />");
}
catch(Exception e)
{
out.print("Could Not Connect to ODBC DSN: " + dbUrl + "<br /><br />" + e.toString());
}

Select ProductID FROM dbo.Products, somethign along those lines after that
Member
Posts: 2,780
Joined: Dec 22 2008
Gold: 3,743.00
Nov 16 2015 08:49pm
Quote (carteblanche @ Nov 17 2015 02:36am)
just go ahead and query the data after you make the connection. post your jdbc call with your exception.


or something along these lines but I'm not good with try statements


query = "select ProductID from dbo.Products";
try {
.......
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 16 2015 08:50pm
Quote (bizzy1999 @ Nov 16 2015 09:48pm)

Select ProductID FROM dbo.Products, somethign along those lines after that


post your EXACT code used to select, using your result set and statement.
Member
Posts: 2,780
Joined: Dec 22 2008
Gold: 3,743.00
Nov 16 2015 08:52pm
Quote (carteblanche @ Nov 17 2015 02:50am)
post your EXACT code used to select, using your result set and statement.


I don't have it anymore I deleted it. Like I said I'm completely stuck...
Go Back To Programming & Development Topic List
123Next
Add Reply New Topic New Poll