d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Help Please (sql Database To Jsp Page) > Paying Fg For Help!
Prev123
Add Reply New Topic New Poll
Member
Posts: 2,780
Joined: Dec 22 2008
Gold: 3,743.00
Nov 17 2015 02:46pm
Quote (carteblanche @ Nov 17 2015 03:57am)
remove all your code and see if it compiles. if it does, then slowly add blocks of code back in until it no longer compiles. that should help you find/understand the compilation error.

i'll check back on this thread tomorrow night after work.

/edit: your variables are wrong. read your compile errors.


I read them, still don't understand how they are wrong.
Member
Posts: 2,780
Joined: Dec 22 2008
Gold: 3,743.00
Nov 17 2015 06:01pm
Quote (bizzy1999 @ Nov 17 2015 08:46pm)
I read them, still don't understand how they are wrong.


New code with no problems still getting an exception thrown:

<!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 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 />");


Statement stmt;



System.out.println("Creating statement...");

stmt = connection.createStatement();

String sql;

sql = "SELECT ProductID, ProductName, UnitPrice FROM Northwind.dbo.Products";

ResultSet rs = stmt.executeQuery(sql);



while(rs.next()){


int id = rs.getInt("UnitPrice");

int is = rs.getInt("ProductID");

String last = rs.getString("ProductName");


// Display values;

System.out.print("ProductID: " + id);

System.out.print(", UnitePrice: " + is);

System.out.print(", ProductName: " + last);



}



%>


 

</body>

</html>








Exception thrown by application class 'sun.jdbc.odbc.JdbcOdbc.createSQLException:6976'
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index

at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6976)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7133)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataInteger(JdbcOdbc.java:3830)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataInteger(JdbcOdbcResultSet.java:5649)
at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(JdbcOdbcResultSet.java:594)
at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(JdbcOdbcResultSet.java:612)
at com.ibm._jsp._Product._jspService(_Product.java:129)
at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:101)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1240)
at [internal classes]
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:215)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1033)
at [internal classes]

This post was edited by bizzy1999 on Nov 17 2015 06:03pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 17 2015 08:04pm
Quote (bizzy1999 @ Nov 17 2015 07:01pm)
New code with no problems still getting an exception thrown:


Exception thrown by application class 'sun.jdbc.odbc.JdbcOdbc.createSQLException:6976'
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index



Good that it compiles!

did you make any attempt to google this issue?

http://stackoverflow.com/questions/6361340/java-sql-sqlexceptionmicrosoftodbc-driver-manager-invalid-descriptor-in
Member
Posts: 1,849
Joined: May 31 2008
Gold: 2,571.50
Nov 18 2015 01:20am
I'm not replying about the problem, the stackover carteblanche posted looks like a good start though.

I am replying to maybe give some pointers

1) Please use {CODE} blocks, it will make it so much easier for us to read through your code and provide you with insights.
- To use code blocks: {CODE} your formated code here! {/CODE} (replace '{}' with '[]')

2) I like how you have multiple System.out.println() to help you debug.
- If you notice your not getting to one of them let us know.

3) Your variable names in your code don't seem to make sense? (at least the ones in the code included in the code block below)

Code below demonstrates the use of {CODE} blocks + has better variable name suggestion commented out.
Code
while(rs.next()){
// Assigning variables
int is = rs.getInt("ProductID"); // int productId;
int id = rs.getInt("UnitPrice"); // int unitPrice;
String last = rs.getString("ProductName"); // int productName;

// Display values;
System.out.print("ProductID: " + id); // ("ProductID: " + productId);
System.out.print(", UnitePrice: " + is); // ("UnitePrice: " + unitPrice);
System.out.print(", ProductName: " + last); // ("ProductName: " + productName);
}


This post was edited by Noobtard on Nov 18 2015 01:21am
Go Back To Programming & Development Topic List
Prev123
Add Reply New Topic New Poll