SQL query in managed bean
hi
i have some idea about setwhereClause() method ..... but in my case i want to use one SQL query (select * from tab )...i dont know how to use ....
(without view object we cant use setwhereclause() method thatsy i have to use sql statement in managed bean ........)
thanks in advance
First of all, you don't want to have any SQL in a managed bean. Managed beans are part of the View layer, and the query should be part of the Model. So what you want to do is add some code to your Model project. So you are trying to do "SELECT * FROM tab". Why not just create a read-only View Object (VO) for the query in the Model (assuming that you are using ADF BC).
Now as for setWhereClause - what do you need in your where clause? You can add where clauses to the query that defines your VO, without needing to resort to using this method. You can even add bind variables for the where clauses, and just drag the ExecuteWithParams method onto your pages, which will give you a place to set the bind variables before executing the query.
You can create your own method in the VO's implementation class, in which you may call setWhereClauseParam to gain more control over how the bind variables are set. Then you make the method available as an operation in the data controls by making it an exposed method to the client interface. You can use setWhereClause in such a method if you need to do so, but there are good performance reasons not to do so if a bind variable will do the job. setWhereClause can also set you up for SQL Injection attacks on your application's security.
Similar Messages
-
How Can I Execute Sql Query in Managed bean?
Hi,
I want to execute sql query in managedbean and get the query result. How can I do?
Best wishes!You can do this by having current Database connection your application is using like this
public static synchronized DBTransaction getDBTransaction(){
FacesContext ctx = FacesContext.getCurrentInstance();
ValueBinding vb = ctx.getApplication().createValueBinding("#{data}");
BindingContext bc = (BindingContext)vb.getValue(ctx.getCurrentInstance());
DataControl dc = bc.findDataControl("AppModuleDataControl");
ApplicationModuleImpl am = ((ApplicationModuleImpl)(ApplicationModule)dc.getDataProvider());
return am.getDBTransaction();
and then user DBTransaction object to create Statement and PreparedStatement you can find those in java doc. -
How to implement sql query in cmp bean?
let's say that i want to join two tables and use grouping, counting and sorting expresion. it is no problem with sql query but what about cmp bean?
of course i can make one bmp bean or session bean and run directly sql expresion, but then what is the point of using cmp beans?
thanks
winnickiIf yout need post-query for filling descriptive colums (eg. department name in emploees) you should build a view object which includes the descriptive colums by joining the relevent tables
-
Query with bind variable, how can use it in managed bean ?
Hi
I create query with bind variable (BindControlTextValue), this query return description of value that i set in BindControlTextValue variable, how can i use this query in managed bean? I need to set this value in String parameter in managed bean.
ThanksPut the query in a VO and execute it the usual way.
If you need to, you can write a parameterized method in VOImpl that executes the VO query with the parameter and then call that method from the UI (as a methodAction binding) either through the managed bean or via a direct button click on the page. -
Hi;
I'm facing problem in running my application on different relational databses b'cos i wrote all my queries for Oracle 8i on Win-NT environment.& now i've to deploy the application on the Linux with MS-SQL database.
How to write sql query in java beans so that it run on all the relational databases without making changes to the query in every bean. OR
How to get the compatible query for different databases?
Thanks in advance.Hey Kalpesh
If you have just the Connection process encapsulated in the Bean, then you can use it as a Singleton object.
Just take a look at the following snippet
public static getConnection(String db) {
if (db.equalsIgnoreCase("ORACLE")) {
if (con != null) {
return con;
} else {
con = DriverManager.getConnection("jdbc:oracle:thin:@"+IP+", " + user + ", " + password);
} else if (db.equalsIgnoreCase("SQLSERVER")) {
if (con != null) {
return con;
} else {
con = DriverManager.getConnection(sqlServerDBConnectionString);
This way you can reduce the number of live connections.
In the JSP, you can access this bean as:
<jsp:useBean id="mb" class="MyBean" scope=whatever/>
Connection con = mb.getConnection("ORACLE");
or
Connection con = mb.getConnection("SQLSERVER");
This way, you can meet your objective.
Check it out. -
How to query data from database and store it into Managed Bean ?
Hi all,
In our application we have requirement to store information within Managed Bean to be accessed by ADF pages.
The information is stored in database tables.
The question is :
What is the efficient / recommended way to do that ?
I do not use apps module to query the data because the information is required in View layer not the model layer
Thank you for your help,
xtantoXtanto,
if the information is stored in the database then the question is if there is a database connect open already. If yes, then why not using this connection to query for the data you want to access and store. Alternatively you can directly open a JDBC connection in a managed bean or access an EJB session bean. However, this comes with the price of an extra database connection.
Make sure the managed bean is in session scope if you want to share the information without re-fetching it
Frank -
Use an SQL Query in a backing bean
hi,
I like to know how to run an SQL query in a backing bean method, this being the code I tried , his goal is to fill the field "cin" with data coming from my database, here is the Code:
public String cb2_action() {
BindingContainer bindings = getBindings();
OperationBinding operationBinding = bindings.getOperationBinding("CreateInsert");
Object result = operationBinding.execute();
if (!operationBinding.getErrors().isEmpty()) {
return null;
DCIteratorBinding dciter =(DCIteratorBinding) bindings.get("PersonneView1Iterator");
Row row=dciter.getCurrentRow();
Statement stmt = this.getDBTransaction().createStatement(1);
try {
ResultSet rs = stmt.executeQuery("select max(cin) from personne");
while( rs.next() ){
row.setAttribute("cin", rs.getInt(1)+1);
} catch (SQLException ex) {
ex.printStackTrace();
return "go";
at run time it give an error at this line : Statement stmt = this.getDBTransaction().createStatement(1);
please check and correct me
thanks in advanceHi,
Initially I would like to say that this should not be used if you are trying to get a PrimaryKey as it would cause serious concurrency issues.
For example lets say that you want whenever you create a new Employee to set his DepartmentId equal to the max department.
We could create a readOnly VO (lets name it MaxDepartmentId) with a query that returns the max departmentId:
select max(Department_Id) as maxDep from DepartmentsAfter that we need to add the MaxDepartmentId VO as a ViewAccessor in our Employees Vo,
override the create() method in the EmployeesRowImpl and add some code like this:
public class EmployeesRowImpl extends ViewRowImpl {
@Override
protected void create(AttributeList attributeList) {
Row r=getMaxDepartmentId().first();
if(r!=null){
Number max=(Number)r.getAttribute("Maxdep");
attributeList.setAttribute("DepartmentId", max);
super.create(attributeList);
}That's all.
If you run this you will see that when you create a new employee it has a default value.
Gabriel. -
Hi all,
I just started doing the XML Xquery programming in my SQL Server 2012 Management Studio. I executed the following code:
--query the XML Blob using a CTE (pulling from the XML file each time) Products
WITH XmlFile (Contents) AS (
SELECT CONVERT (XML, BulkColumn)
FROM OPENROWSET (BULK 'H:\Products.xml', SINGLE_BLOB) ) AS XmlData
SELECT *
FROM XmlFile
GO
I got the the following Msg:
Msg 491, Level 16, State 1, Line 4
A correlation name must be specified for the bulk rowset in the from clause.
How can I specify the correction name for the bulk rowset in my project?
Please kindly help, advise and respond.
Thanks in advance,
Scott ChangHello Scott,
You have to assign a table alias for the OPENROWSET =>
--query the XML Blob using a CTE (pulling from the XML file each time) Products
WITH XmlFile (Contents) AS (
SELECT CONVERT (XML, BulkColumn)
FROM OPENROWSET (BULK 'H:\Products.xml', SINGLE_BLOB) AS MyXML ) AS XmlData
SELECT *
FROM XmlFile
GO
Olaf Helper
[ Blog] [ Xing] [ MVP] -
Looking for a SQL query to get all the possible Alert Messages from the Rules in a Management Pack
For reporting, I'm looking to get a SQL query of all the possible Alert Messages for Rules configured in a Management Pack (not necessarily the ones that have thrown alerts). I can do this for Monitors, but not for Rules.
The configured alert messages for the Management Pack Monitors
go like this: ManagementPack > MonitorView> RuleModule > RuleModule.Alert Message > Localized Text
The configured alert messages for the Management Pack Rules
should go something like this, but there is a missing link: ManagementPack > RuleView > RuleModule > ? Missing Link ? > Localized Text
The Rules are tied to the Module, but I don't see a connection from the RulesModule to the Alert Message that I see in the LocalizedText. The Rule names do not always equal the Alert name.
Can someone provide the missing link?Hi,
please try below powershell code to find the corresponding management pack for specific alert:
$Alert = get-scomalert | where {$_.Name -like 'Agent Proxy Not Enabled*'} | select -first 1
If ($alert.IsMonitorAlert -eq "True") {
write-host "Ths is a monitor-generated alert"
get-scommonitor -ID $Alert.MonitoringRuleID | select Enabled, DisplayName, ManagementPack
else
write-host "This is a rule-generated alert"
get-scomrule -ID $Alert.MonitoringRuleID | select Enabled, DisplayName, ManagementPack
In addition, please also refer to the below link:
http://blogs.technet.com/b/mazenahmed/archive/2011/12/02/using-powershell-to-map-opsmgr-active-alert-to-its-corresponding-rule-monitor-and-management-pack-name.aspx
Regards,
Yan Li
Regards, Yan Li -
public String select()
try
Connection conn = DriverManager.getConnection (url, dbUser, dbPassword);
Statement stmt = conn.createStatement();
String query = "SELECT ID, name, summary, start_time, end_time FROM cruises
WHERE ID = "'" + request.getParameter("IPName") + "%'";
rs = stmt.executeQuery(query);
I don't think I can apply what I've got to the bean, but not sure how to go about it. Pls. give me some insight..What exactly is your problem.
You can include any SQL statements in a bean. In fact, that is way to make beans persistent. I put all SQL-statements that relate to a bean in the bean (select, update, insert, delete).
You're SQL does seem a bit strange to me though. I think the query should be like this:
SELECT ID, name, summary, start_time, end_time FROM cruises
WHERE ID LIKE '" + request.getParameter("IPName") + "%'"
= -> LIKE
"'" -> '"
B. -
SQL query generating data in SQL management studio but not in CUIC interface
Hello,
I'm working on a UCCE 9.0 system
I created SQL query for a report.
Whenever I run the query inside the SQL management studio, it works and generates data, but when I run it in the CUIC interface it works but generates nothing. As you can see in the below snapshot, it contains 209 records that are not being displayed.
Any help would be greatly apprciatedIs it a custom report ? Can you right click on your Custom Report and click on Edit Views. You need to check whether you have Grid Headers Listed.
Regards,
Senthil -
HI
I want a sql query i.e., all employees list which are having lessthan maximum salary of manager in same departmnet;
my table is like this
employees
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
if need the department table
departments:
DEPARTMENT_ID
NOT NULL NUMBER(4)
DEPARTMENT_NAME
NOT NULL VARCHAR2(30)
MANAGER_ID
NUMBER(6)
LOCATION_ID
NUMBER(4)Try this:
select
employees.last_name || ', ' || employees.first_name “Employee”,
employees.salary “Emp Salary”,
sub.salary “Mgr Salary”,
employees.department_id “Department”
from
employees,
( select
mgr.department_id dept,
max(mgr.salary) salary
from
employees,
employees mgr
where
employees.mgr = mgr.employee_id
group by
mgr.department_id) sub
where
employees.department_id = sub.dept
and employees.salary < sub.salary
Jeff -
SQL query to assign multiple concurrent programs to concurrent manager.
Hello,
Do you have any script to assign a list of concurrent Program to distinct Concurrent Managers . Actually there are more than 100 programs need to be assigned to manager.ut
We can do it from front end,but it will take quite long time to finish this task.
Could you please help me on this.
Thanks & Regards,
Saroj.What are the details do i need to check before assign them to Custom Managers.
What do you mean by details you need to check?
Kindly provide me a sql query to get all the details before proceeding to assigning managers.
Concurrent programs definitions can be found in the following tables/views:
FND_CONCURRENT_PROGRAMS
http://etrm.oracle.com/pls/et1211d9/etrm_pnav.show_object?c_name=FND_CONCURRENT_PROGRAMS&c_owner=APPLSYS&c_type=TABLE
FND_CONCURRENT_PROGRAMS_TL
http://etrm.oracle.com/pls/et1211d9/etrm_pnav.show_object?c_name=FND_CONCURRENT_PROGRAMS_TL&c_owner=APPLSYS&c_type=TABLE
FND_CONCURRENT_PROGRAMS_VL
http://etrm.oracle.com/pls/et1211d9/etrm_pnav.show_object?c_name=FND_CONCURRENT_PROGRAMS_VL&c_owner=APPS&c_type=VIEW
Thanks,
Hussein -
MS SQL query to get Subscription list from Operations Manager
Hi Experts,
Is there anyway get Subscription list from Operations Manager DB using SQL query? I lost subscription list, and need to create subscription as it was. Very urgent.
Thanks in advance.
Regards
Karthick MHi,
Hope the powershell command Get-SCOMNotificationSubscription can be helpful for you:
Get-SCOMNotificationSubscription
Retrieves a list of notification subscriptions.
https://technet.microsoft.com/en-us/library/hh918490(v=sc.20).aspx
Regards,
Yan Li
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected] -
Managing beans based on URL query parameters
I was just reading this thread with interest, but it didn't come to the conclusion that I need.
http://forum.java.sun.com/thread.jsp?forum=427&thread=441432
In that thread, there were two screens: a table of links to employees and an "edit employee" page. The solution was to use the command_action on the list create an "employee data" bean, which could then be edited on the "edit employee" page.
My problem is that I need to create some session beans based on query parameters in the URL. Using the example above, I'd have something like: http://localhost/app/editEmployee?empNo=38
Why? Because the user can bookmark the edit employee page, have two
browser windows open (which would require two seperate employee data beans), etc... and we need to handle that. It looks like
that means I can't use the solution in the above thread.
My current thought is to create a managed-bean with request scope and have it create the EmployeeData bean.
Another idea is to somehow initialize the bean with managed-properties
<managed-bean>
<managed-bean-name>EmpBean</managed-bean-name>
<managed-bean-class>com.mycompany.EmpBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>employeeID</property-name>
<value-ref>queryParamBean</value-ref>
</managed-property>
</managed-bean>
<!--
just returns FacesContext.getCurrentInstance().getServletRequest().getParameter("id")
-->
<managed-bean>
<managed-bean-name>queryParamBean</managed-bean-name>
<managed-bean-class>com.mycompany.QueryParamBean</managed-bean-class>
<managed-bean-scope>none</managed-bean-scope>but that seems kinda hacky. Any other ideas?Excellent, using requestScope gets rid of the queryParamBean hack from my first post. For some reason I thought value-ref evaluatations only resolved against stuff the VariableResolver can see. That's not the case. Thanks.
Unfortunately, this bean really wants to be cached on the session, not the request. I suppose it would be possible to have EmpBean delegate to a bean which is actually cached on the session, but that feels like a hack too (and is a lot of glue code).
So, I think I'm back to the factory, which can handle creating the bean from the query params, caching it, and putting it on the servlet request. I also got a visit from Captain Obvious and realized that the factory could just be a scriplet.
<% BeanCreator.createBean("com.company.EmpBean", request.getParameter("id")); %>which also isn't great, but is perhaps easier to understand than the BeanCreator from above. I looked into using EL Functions in the variable resolver for the factory, but it doesn't look like that's possible. It's probably possible to extend VariableResolver to add factory methods for managed-beans, which might be the cleanest solution. I'm thinking something like
<managed-bean>
<managed-bean-name>Emp</managed-bean-name>
<managed-bean-factory>
<factory-name>com.company.BeanFactory.getBean</factory-name>
<bean-class>com.company.EmpBean</bean-class>
<arg-value-ref>sessionScope.id</arg-value-ref>
</managed-bean-factory>But for now, the current two hacks are:
#1: to create a URL use plain html <href>.
#2: use a factory method (varying implementions) to create the bean, cache it, and put it on the servlet request
Maybe you are looking for
-
AHT Apple Hardware Test Download & Flash Drive
Hi guys, I really need to test the hardware on a 13" MBP. Full spec below. The machine has Yosemite installed & I don't have the original install disc. Does anyone know where to download the Apple Hardware Test (AHT) files & how to go about using it
-
i put in include form xxxx endform. and i get error why? what should i do?
-
i was doing an in-app puchase and it said to contact apple support and another said purchased failed cannot connect to itunes store, how do i fix it?
-
MSDN article KB955078 - System state backups failing in MSCS environment
Hello, We have a an MSCS cluster running on Windows 2008 with SQL server 2008. When we run a system state backup on the Passive node we get the error mentioned in Microsoft article KB955078 because of the SAP executables installed onto one of the sha
-
Stcok type H values are not added into report
Hello all, I am facing problem with inventory management. Here we have nearly 15 plants. 10 are already there and 5 are newly added in the last month. For the previous 10 plants we are getting the valuated stock perfectly, but i am checking for the