GeeCON Prague 2014*
The moose likes JDBC and the fly likes connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "connection" Watch "connection" New topic
Author

connection

Abebe Belew
Greenhorn

Joined: Jul 21, 2004
Posts: 19
Action
======
package app;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.io.*;
import java.lang.*;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import app.pcSQLException;
import app.db_connection;

public class RegisterAction extends Action{

private String selectstr ;
private String mrn = "";

public ActionForward execute (ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{

String mrn = ((RegisterForm) form).getMrn();

javax.sql.DataSource dataSource;
java.sql.Connection conn;

try {
dataSource = getDataSource(request);
conn = dataSource.getConnection();

try {
if(mrn.length() != 0){
selectstr = db_connection.queryExecute(mrn, conn);
conn.close();
}

} catch (pcSQLException e) {
System.out.println ("Error Executing Query: " + e.getMessage());
}

} catch (Exception e) {
System.out.println (e.getMessage());
}

HttpSession session = request.getSession(true);
session.setAttribute("registerSess", selectstr);

return mapping.findForward("success");

}
}

my bean:
=======
package app;

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
import java.sql.*;

public class db_connection {

public static String queryExecute(String mrn, Connection conn)
throws pcSQLException {

try {
String querytext = null;
String strQuery = "select mrn from qdsn.procedurea where mrn = '" + mrn + "' ";
Statement stmt = conn.createStatement();
System.out.println("conn = " + conn);
ResultSet rset = stmt.executeQuery(strQuery);

while (rset.next()) {
querytext = rset.getString(1);
System.out.println("this is result from bean" + querytext);
return querytext;
}//end while

} catch (Exception e) {
throw new pcSQLException();
}//end catch
return null;
}
}//end db_connection

Error Message while trying to compile:
======================================

queryExecute() in app.db_connection cannot be applied to (java.lang.String,java.sql.Connection)
[javac] selectstr = db_connection.queryExecute(mrn, conn);
[javac] ^
[javac] 1 error

Please help!!!
Thanx in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

"sewsew",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeff Walker
Ranch Hand

Joined: Apr 25, 2004
Posts: 116
SewSew (whoever that is),

I managed to copy your code into a project in Eclipse 3.0, and build it all except for the line:
String mrn = ((RegisterForm) form).getMrn();

which I had to hack to:
String mrn = "whatever, we just need to compile it, not run it";

I had no build problems at all after that!

I suggest you have a dependency error in your project, and need to "Rebuild All" your project.
My next useless suggestion, is to go through the Warning Levels in your IDE, and see if your warning levels are way too high. I suspect it doesn't like the switching your doing when you use both "java.SQL.Connection" and plain old "Connection" by itself, in your imports and method declarations.
Good luck SewSew!

-Jeff Walker
 
GeeCON Prague 2014
 
subject: connection