Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

connection  RSS feed

Abebe Belew
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package app;
import org.apache.struts.action.*;
import javax.servlet.http.*;
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);

} 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.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 ( {
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
Posts: 66205
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

Forum Bartender
Jeff Walker
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!