Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 29th, 2003, 01:07 PM
Registered User
 
Join Date: Jun 2003
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to gargon1
Default java.sql.SQLException: Column 'somenam' not found.

Hello,
Using the connect() method in the example below I am able to query the mysql database with no problem. However, when I call the viewUsers() method in a jsp I receive the following message "java.sql.SQLException: Column 'somename' not found.". In fact it would only work when I change the column name to dept. All other column name result in the error I mentioned earlier. Please Help!

######### JAVA BEAN ##############################

// timeclock.java
package tclock;

import java.sql.*;
import java.util.*;


public class timeclock {

    String error;
    Connection con;

public timeclock() { }

public void connect() throws ClassNotFoundException,
                SQLException,
                Exception {
    try {
      //Class.forName("com.mysql.jdbc.Driver").newInstance ();
      Class.forName("org.gjt.mm.mysql.Driver").newInstan ce();
      System.out.println("JDBC driver loaded");

      con = DriverManager.getConnection
              ("jdbc:mysql://localhost/time_card?user=dalma&password=");
      System.out.println("Database connection established");

      Statement stmt = con.createStatement();

      ResultSet rs = stmt.executeQuery("SELECT * FROM time_sheet");
      //ResultSet rs= stmt.executeQuery("Select fname, lname FROM time_sheet");
      while (rs.next()) {
        String title = rs.getString("fname");
    String title1 = rs.getString("lname");
    String title2 = rs.getString("dept");
    //String title3 = rs.getInteger("id");
        //float price = rs.getint("Price");

        System.out.println(title1);
      }
    } catch (ClassNotFoundException cnfe) {
      System.out.println("ClassNotFoundException: Could not locate driver");
    } catch (SQLException cnfe) {
      System.out.println("SQLException: Could not connect to database");
    } catch (Exception e) {
      System.out.println
              ("An unknown error occurred while connecting to database");
    }
    }

public void disconnect() throws SQLException {
  try {
    if ( con !=null ) {
    con.close();
    }
   } catch(SQLException sqle) {
        System.out.println("Unable to close database connection.");
      }
    }

public ResultSet viewUsers() throws SQLException, Exception {
    ResultSet rs= null;
    try {
        //String queryString=("SELECT * FROM time_sheet");
        Statement stmt = con.createStatement();
        //rs = stmt.executeQuery(queryString);
    rs = stmt.executeQuery("SELECT * FROM time_sheet");
    } catch (SQLException sqle) {
        error = "SQLException: Could not execute query.";
        throw new SQLException(error);
    } catch (Exception e) {
        error = "An exception has occured while retrieving departments,";
        throw new Exception(error);
    }
    return rs;
}

public static void main (String[] args)
{
    timeclock sdb = new timeclock();

    try
    {
        sdb.connect();

    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}


}

################# JSP #######################################

<%@page language="java" contentType="text/html" import="java.sql.*, java.util.*" errorPage="error.jsp" %>
<jsp:useBean id="mytime" class="tclock.timeclock"/>

<html>
<head><title>JSP Page</title></head>
<body>
<H1>Virgin Islands Water & Power Authority</H1>
<table border="1">
 <tr>
 <td><b><B>Clock Number:</b></td>
 <td><b><B>Date:</b></td>
 <td><b><B>Time:</b></td>
 <td><b><B>User ID:</b></td>
 <td><b><B>First Name:</b></td>
 <td><b><B>Last Name:</b></td>
 <td><b><B>Departments:</b></td>
 <td><b><B>Status:</b></td>
 <td><b><B>Record Number:</b></td>
 </tr>
<%
mytime.connect();
ResultSet rs = mytime.viewUsers();
while (rs.next()) {
%>
<tr>
<td><%= rs.getString("fname") %></td>
</tr>
<%
 }
%>

</table>
</body>
</html>
Reply With Quote
  #2 (permalink)  
Old July 1st, 2003, 10:39 PM
Registered User
 
Join Date: Jul 2003
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

this may be because the table being accessed in the database may not have a column "somename"

Ram
Reply With Quote
  #3 (permalink)  
Old July 11th, 2005, 08:02 AM
gbd gbd is offline
Registered User
 
Join Date: Jul 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to gbd Send a message via Yahoo to gbd
Default

Hi,

I know it shouldnt be very useful but I got quite the same problem with hibernate generated queries.

I use hibernate for a <one-to-many> relation and the generated SQL code, though it is perfectly correct (tried it against my mysql.user system table), sends me the same error

### part of a long stack trace ###
Hibernate: /* from MySQLUser where user='lg' and host='localhost' */ select mysqluser0_.host as host, mysqluser0_.user as user, mysqluser0_.pwd as pwd10_, mysqluser0_.sel as sel10_, mysqluser0_.del as del10_, mysqluser0_.ins as ins10_, mysqluser0_.upd as upd10_, mysqluser0_.cre as cre10_, mysqluser0_.tmp as tmp10_, mysqluser0_.rld as rld10_, mysqluser0_.Drp as Drp10_, mysqluser0_.Sup as Sup10_ from MySQLUser_mod mysqluser0_ where user='lg' and host='localhost'

24696 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: S0022

24696 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Column 'pwd10_' not found.

I'm quite lost with it, and if you ever get an answer I might be interested.

Sorry not to help :(




Reply With Quote
  #4 (permalink)  
Old August 5th, 2005, 12:35 PM
Registered User
 
Join Date: Aug 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had the same error message and did manage to solve it. I'm not sure if the error I had was from the same root cause but here's what I found...

What I believe caused my error was that I was selecting an object and then doing an inner join fetch for the same object. I believe what is happening is that if you select an object (in this case "t.member") that it does the eager fetch for you.

Below are 2 examples that should make this explanation more clear...

THIS WILL CAUSE AN ERROR (notice that I'm selecting "t.member" as well as doing an "inner join fetch t.member")...

    <query name="get.topic.replies.by.topic.id.ascending"><![CDATA[
        select t.id, t.member, t.group.id, t.group.name

        from Topic as t
        inner join fetch t.member
        inner join fetch t.group
    ]]>
    </query>




THIS WILL NOT CAUSE THAT ERROR (note that I'm selecting t.member but I'm NOT doing "inner join fetch t.member")

    <query name="get.topic.replies.by.topic.id.ascending"><![CDATA[
        select t.id, t.member, t.group.id, t.group.name

        from Topic as t
        inner join fetch t.group
    ]]>
    </query>


Again, I'm not sure if this is what is happening in your case but I hope it somehow helps you out.

Best of luck!


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
java.sql.SQLException muthumari_p2003@yahoo.com SQL Server 2000 1 March 22nd, 2006 08:57 AM
java.sql.SQLException: Invalid column type Che Guevara Java Databases 1 July 1st, 2005 07:39 AM
java.sql.SQLException: Invalid argument(s) in call dharmendra_rh Java Databases 1 May 5th, 2005 02:58 AM
java.sql.SQLException: [Microsoft][ODBC Driver Man pvsharinath@gmail.com Java Databases 1 May 5th, 2005 02:40 AM
java.sql.SQLException: Error loading JDBC Driver jdphjp Java Databases 1 August 5th, 2004 12:46 AM



All times are GMT -4. The time now is 05:28 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.