Skip to content
Advertisement

Tag: sql

Using Prepared Statements to set Table Name

I’m trying to use prepared statements to set a table name to select data from, but I keep getting an error when I execute the query. The error and sample code is displayed below. Any thoughts on what might be causing this? Answer A table name can’t be used as a parameter. It must be hard coded. So you can

How can I avoid ResultSet is closed exception in Java?

As soon as my code gets to my while(rs.next()) loop it produces the ResultSet is closed exception. What causes this exception and how can I correct for it? EDIT: I notice in my code that I am nesting while(rs.next()) loop with another (rs2.next()), both result sets coming from the same DB, is this an issue? Answer Sounds like you executed

Does JPA support mapping to sql views?

I’m currently using Eclipselink, but I know now days most JPA implementations have been pretty standardized. Is there a native way to map a JPA entity to a view? I am not looking to insert/update, but the question is really how to handle the @Id annotation. Every entity in the JPA world must have an ID field, but many of

How to convert java.util.Date to java.sql.Date?

I am trying to use a java.util.Date as input and then creating a query with it – so I need a java.sql.Date. I was surprised to find that it couldn’t do the conversion implicitly or explicitly – but I don’t even know how I would do this, as the Java API is still fairly new to me. Answer tl;dr How

Advertisement