Ma7T
asked on
SQL query in a java bean
My SQL Query is:
ResultSet RS = SQLStmt.executeQuery("SELE CT * FROM links;");
Question:
If I pass a string into the method (called SQLVar for example), how do I pass this into my SQL statement so i have something like this:
ResultSet RS = SQLStmt.executeQuery("SELE CT * FROM links where description like SQLvar;");
Thanks,
Matt
ResultSet RS = SQLStmt.executeQuery("SELE
Question:
If I pass a string into the method (called SQLVar for example), how do I pass this into my SQL statement so i have something like this:
ResultSet RS = SQLStmt.executeQuery("SELE
Thanks,
Matt
ResultSet RS = SQLStmt.executeQuery("SELE CT * FROM links where description like '"+SQLvar+"';");
ASKER
Also - if I create a session bean, how do i discard the session - for example is a user logs out?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> if I create a session bean, how do i discard the session
session.invalidate();
session.invalidate();
ASKER
Hello again Objects.
I think your code works - unfortunately when I ran it I started getting an exception, so i put all my code back how it was and I can't seem to get rid of the exception. Can you cast your expert eye over it - I can't seem to find where the error lies:
try
{
ObjConn = DriverManager.getConnectio n(url, "user", "password");
SQLStmt = ObjConn.createStatement();
ResultSet RS = SQLStmt.executeQuery("SELE CT * FROM database;");
ResultSetMetaData OutputMD = RS.getMetaData();
iNumColumns = OutputMD.getColumnCount();
while(RS.next())
{
Vector Vectortemp = new Vector();
for(int i=1;i<=iNumColumns;i++)
{
Vectortemp.addElement(RS.g etObject(i ));
}
VectorA.addElement(Vectort emp);
}
SQLStmt.close();
RS.close();
ObjConn.close();
}
Any ideas.
(i've upped the points because you've been so helpful)
I think your code works - unfortunately when I ran it I started getting an exception, so i put all my code back how it was and I can't seem to get rid of the exception. Can you cast your expert eye over it - I can't seem to find where the error lies:
try
{
ObjConn = DriverManager.getConnectio
SQLStmt = ObjConn.createStatement();
ResultSet RS = SQLStmt.executeQuery("SELE
ResultSetMetaData OutputMD = RS.getMetaData();
iNumColumns = OutputMD.getColumnCount();
while(RS.next())
{
Vector Vectortemp = new Vector();
for(int i=1;i<=iNumColumns;i++)
{
Vectortemp.addElement(RS.g
}
VectorA.addElement(Vectort
}
SQLStmt.close();
RS.close();
ObjConn.close();
}
Any ideas.
(i've upped the points because you've been so helpful)
what errors u getting?
ASKER
I'm not sure - I've got a crude way of checking:
catch(SQLException ConnectEx)
{
iNumColumns = 32;
System.err.println(Connect Ex.getMess age());
}
I return iNumColumns to the JSP page and output it to the screen.
All i know is iNumColumns = 32
catch(SQLException ConnectEx)
{
iNumColumns = 32;
System.err.println(Connect
}
I return iNumColumns to the JSP page and output it to the screen.
All i know is iNumColumns = 32
> System.err.println(Connect Ex.getMess age());
what does that line print to log?
> SQLStmt.close();
> RS.close();
> ObjConn.close();
order should be:
RS.close();
SQLStmt.close();
ObjConn.close();
what does that line print to log?
> SQLStmt.close();
> RS.close();
> ObjConn.close();
order should be:
RS.close();
SQLStmt.close();
ObjConn.close();
ASKER
If i browse to tomcat/logs where i assume the logs are there are about 5 different log files whih contain loads of data. So i've moved them into a file called temp so that when i reload the page it creates a new log file. But this doesn't happen.
How do i find the particular log of this event?
How do i find the particular log of this event?
what version of tomcat?
did u change the ordering of the close?
did u change the ordering of the close?
ASKER
Yep, changed the order.
Version of tomcat is 5.0.16
The only thing that i have changed since it was working was the page that the method is called from but i can't see his having any effect on the method throwing an exception.
Version of tomcat is 5.0.16
The only thing that i have changed since it was working was the page that the method is called from but i can't see his having any effect on the method throwing an exception.
you could try getting rid of that ; at the end of the sql statement.
not sure what 5.0 does with its logs and it probably depends on your setup anyway.
if it helps the log for my local tobcat webapp in 4.1 is localhost_log.yyyy-mm-dd.t xt
not sure what 5.0 does with its logs and it probably depends on your setup anyway.
if it helps the log for my local tobcat webapp in 4.1 is localhost_log.yyyy-mm-dd.t
ASKER
Fixed it!!!!
dont worry i was being an idiot.
It was further above in the code, i had :
ClassforName("var")
instead of ClassforName(var)
Thanks a lot for your help though, I found the log file and it was that that pointed me to my stupid mistake.
dont worry i was being an idiot.
It was further above in the code, i had :
ClassforName("var")
instead of ClassforName(var)
Thanks a lot for your help though, I found the log file and it was that that pointed me to my stupid mistake.