Executing SQL query in portal database
Hi ,
I wish to do a simple POC . I need to create a table from NWDS , populate it with some data and then access the table data using an sql query . I am aware how to create a table but I am not sure where exactly to write the query .
What I would like to understand is
1) If I create a table where would that table get created (The database) ?
2) Where would I write that query in NWDS ?
3) How would I execute that query in that database ?
Please help for the same .
(Needless to say that I always award points )
Regards
Deepak Singh
Hi Gopal ,
Thanks for the reply .This is what I did . I am pasting the whole code of the class that I am using to do the POC .
package com.gravity;
import java.sql.Connection;
import java.sql.Statement;
import java.util.Hashtable;
import javax.naming.InitialContext;
import javax.sql.DataSource;
/*import sun.jdbc.odbc.ee.DataSource;/
@author Administrator
To change the template for this generated type comment go to
Window>Preferences>Java>Code Generation>Code and Comments
public class DataHandling {
public static void DataPost(){
Connection con = null ;
try {
Added code
Hashtable env = new Hashtable();
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
System.out.println("initial_context_factory put ");
env.put(javax.naming.Context.PROVIDER_URL, "gms29:50004");
System.out.println("provide_url put ");
env.put(javax.naming.Context.SECURITY_PRINCIPAL, "j2ee_admin");
System.out.println("security_principal put ");
env.put(javax.naming.Context.SECURITY_CREDENTIALS, "gravity");
env.put("domain", "true");
env.put("force_remote", "true");
System.out.println("security_credentials put ");
InitialContext iCtxt = new InitialContext(env);
System.out.println("Object made for initial context ");
DataSource ds = (DataSource) iCtxt.lookup("jdbc/my_db");
System.out.println("Datasource obtained ");
try {
con = ds.getConnection();
Statement stmt = con.createStatement();
String query1 ="insert into EmpData (EMPCODE,EMPNAME) VALUES('naveen',125188)";
String query2 ="insert into EmpData (EMPCODE,EMPNAME) VALUES('deepak',125189)";
String query3 ="insert into EmpData (EMPCODE,EMPNAME) VALUES('rajeev',125190)";
stmt.executeUpdate(query1);
stmt.executeUpdate(query2);
stmt.executeUpdate(query3);
}catch (Exception e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
} finally {
try {
con.close();
}catch (Exception e) {
e.printStackTrace();
public static void main (String[] args){
System.out.println("Hello");
DataPost();
I have imported all the driver jar files and sapj2eeclient.jar in the classpath .
Also the drivers found in the path
172.16.161.11\usr\sap\EP1\DVEBMGS00\j2ee\cluster\server0\bin\ext\com.sap.portal.jdbcdrivers
have all been added to the classpath .(Not sure if this is required)
Let me know what you find wrong in my code and in the meanwhile I will try to implement what you suggested .
Regards
Deepak Singh
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 execute SQL Query in Code behind Using infopath 2010?
Hi,
I've repeatable on infopath form, and want bind it throuth code behind from SQL table. My question is that how to execute SQL Query in code behind from infopath as well as how would get Query result to bind repeatable control?
Thanks In Advance
Shoeb AhmadHello,
You first need to add new SQL DB connection then you need execute connection from code behind.
See below link to create new connection
http://office.microsoft.com/en-in/infopath-help/add-a-data-connection-to-a-microsoft-sql-server-database-HP010092823.aspx:
http://www.bizsupportonline.net/infopath2010/connect-infopath-2010-sql-server-2008-table.htm
Then use below code to execute this connection:
AdoQueryConnection conn = (AdoQueryConnection)(this.DataConnections["Data connection name"]);
string origCommand = Select * from tablename;
conn.Command = origCommand;
conn.Execute();
Finally bind your table:
http://www.bizsupportonline.net/infopath2007/4-way-programmatically-add-row-repeating-table.htm
http://stevemannspath.blogspot.in/2010/09/infopath-20072010-populate-repeating.html
Hope it could help
Hemendra:Yesterday is just a memory,Tomorrow we may never see
Please remember to mark the replies as answers if they help and unmark them if they provide no help -
Hi All,
I am working with labview application.
The database being used is Access.
The tables i have to use contains the special symbol - (not underscore.)
Let the table name be user-data
When i am executing the query select * from user-data its showing
error message syntax error in from clause.
I tried just typing the query in access also and got the same error.
I believe its because of the usage of the special character other than underscore in table name
Many applications using the same database is running in VB already.So there is no way for me to rename the table.
I know i am asking an invalid question.But still....
Is there any way for me to use the same table name and execute sql query.
Thanks in advanceThere should be. Try putting the table name in quotes - some DBMS use single quotes, some use double quotes. For example say the table name has a space in it. Try something like:
select * from 'a funny table';
or
select * from "a funny table"; (Actually, I think I'd try this one first...)
Failing this, you have two choices: change the name of the table, or dump Access and go with a real DBMS - which you will probibly want to do anyway because it will only be a matter of time before you start hitting a performance wall. Access is particularly bad if you have more than one process making a connection to it at a time. Interms of alternatives, there are a couple really good open-source products out there, as well as no-cost versions of Oracle and SQL-Server.
Mike...
Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion
"... after all, He's not a tame lion..."
Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps -
I want to execute SQL query in the JavaBean.
Is there any problem in the following code.
There is no error message, but the database do not update. And I try to use JSP , it is ok. What is the problem in JavaBean ??
How to execute SQL in JavaBean ???
Please help ! Thank you !
test.jsp - call UserTrace.java
UserTrace.java - execute SQL
Code:
** test.jsp **
<%@ page language="java" contentType="text/html" %>
<%@ page import="user.*, java.util.*" %>
<jsp:useBean id="usertrace" class="user.UserTrace" scope="session" />
<%
if (session.isNew())
session.setAttribute("usertrace", usertrace);
session.setMaxInactiveInterval(15);
%>
** UserTrace.java **
package user;
import java.util.*;
import javax.servlet.http.*;
import java.io.*;
import java.beans.*;
import java.sql.*;
import user.*;
public class UserTrace implements javax.servlet.http.HttpSessionBindingListener {
private Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String sql;
public void valueBound(HttpSessionBindingEvent event) {
public void valueUnbound(HttpSessionBindingEvent event) {
try {
Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/test?user=abc&password=abcd");
stmt = con.createStatement();
sql = "insert into list(username, session_id) values ('mary', 'xxxxxxxxx')";
int count = stmt.executeUpdate(sql);
catch (ClassNotFoundException e) {
catch (SQLException e) {
}Hi,
U can use the following code:
/********** IMPORTING PACKAGES AND CLASSES *******/
// General package id
package id;
//Import the Vector class as this bean handles Vector.
import java.util.Vector;
//Import the SQL class to create the connections,statement,resultset etc.,
import java.sql.*;
//Import the SQL Types to call the setNull Method.
import java.sql.Types.*;
/* Main Class */
public class dataBean
/*********** Global Declarations ********/
// To create the connection object
Connection con;
// To create the Statement object
Statement stmt;
// To create the PreparedStatement object
PreparedStatement psmt;
// To Handle the ResultSet
ResultSet rs;
// Most of the method need to hold the querystring for which qryString variable declare globally.
String qryString=null;
/************ METHODS **************/
/* To set the connection object
con - Connection object
public void setConnection(Connection con)
try
this.con = con;
catch(Exception e)
/* insertRecord with column type argument
tblNameString - Name of the Table
dataVector - vector contains the values according to the table order
eg., element(0) has first field, element(1) has second field vice versa
colType - String array contains type of all the fields.
return true - if record inserted successfully
fase - if insertion fails
public boolean insertRecord(String tblNameString,Vector dataVector,String colType[])
boolean sucFlag=false;
try
String commaString = "";
int fieldCount = dataVector.size();
for (int i=0;i<fieldCount-1;i++)
commaString +="?,";
commaString+="?";
if (fieldCount > 0)
qryString = "insert into "+tblNameString+" values ("+commaString+")";
psmt = con.prepareStatement(qryString);
for(int i=0;i<colType.length;i++)
if (colType.equals("I"))
psmt.setInt(i+1,Integer.parseInt(dataVector.elementAt(i).toString()));
else if (colType[i].equals("F"))
psmt.setFloat(i+1,Float.parseFloat(dataVector.elementAt(i).toString()));
else if (colType[i].equals("S") || colType[i].equals("D"))
psmt.setString(i+1,dataVector.elementAt(i).toString());
else if (colType[i].equals("IN")||colType[i].equals("FN"))
psmt.setNull(i+1,java.sql.Types.NUMERIC);
else if (colType[i].equals("SN"))
psmt.setNull(i+1,java.sql.Types.VARCHAR);
else if (colType[i].equals("DN"))
psmt.setNull(i+1,java.sql.Types.DATE);
int sucCnt = psmt.executeUpdate();
if (sucCnt > 0) sucFlag=true;
catch(Exception e)
return sucFlag;
/* insertRecord without column type argument
tblNameString - Name of the Table
dataVector - vector contains the values according to the table order
eg., element(0) has first field, element(1) has second field vice versa
return true - if record inserted successfully
fase - if insertion fails
public boolean insertRecord(String tblNameString,Vector dataVector)
boolean sucFlag=false;
Vector colType = getColumnType(tblNameString);
try
String commaString = "";
int fieldCount = dataVector.size();
for (int i=0;i<fieldCount-1;i++)
commaString +="?,";
commaString+="?";
if (fieldCount > 0)
qryString = "insert into "+tblNameString+" values ("+commaString+")";
psmt = con.prepareStatement(qryString);
for(int i=0;i<colType.size();i++)
if (colType.elementAt(i).toString().equals("I"))
if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
psmt.setNull(i+1,java.sql.Types.NUMERIC);
else
psmt.setLong(i+1,Long.parseLong(dataVector.elementAt(i).toString()));
else if (colType.elementAt(i).toString().equals("F"))
if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
psmt.setNull(i+1,java.sql.Types.NUMERIC);
else
psmt.setDouble(i+1,Double.parseDouble(dataVector.elementAt(i).toString()));
else if (colType.elementAt(i).toString().equals("S"))
if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
psmt.setNull(i+1,java.sql.Types.VARCHAR);
else
psmt.setString(i+1,dataVector.elementAt(i).toString());
else if (colType.elementAt(i).toString().equals("D"))
if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
psmt.setNull(i+1,java.sql.Types.DATE);
else
psmt.setString(i+1,dataVector.elementAt(i).toString());
int sucCnt = psmt.executeUpdate();
if (sucCnt > 0) sucFlag=true;
catch(Exception e)
return sucFlag;
/* insert particular fields
tblNameString - Name of the Table
dataVector - vector which contains the values according to the table order
eg., element(0) has first field, element(1) has second field vice versa
colType - String array contains type of all the fields.
return true - if record inserted successfully
fase - if insertion fails
public boolean insertRecordPart(String tblNameString,Vector dataVector,String colType[])
boolean sucFlag=false;
String fieldString=" ";
try
String commaString = "";
int fieldCount = dataVector.size();
for (int i=0;i<(fieldCount/2)-1;i++)
commaString +="?,";
commaString+="?";
if (fieldCount > 0)
String valueString[]= new String[fieldCount];
for (int i=0,j=0;i<fieldCount;i+=2,j++)
fieldString=fieldString+dataVector.elementAt(i)+",";
valueString[j]=dataVector.elementAt(i+1).toString();
if (fieldString.substring(fieldString.length()-1,fieldString.length()).equals(","))
fieldString=fieldString.substring(0,fieldString.length()-1);
qryString = "insert into "+tblNameString+"("+fieldString+") values ("+commaString+")";
psmt = con.prepareStatement(qryString);
for (int i=1,j=0;i<fieldCount;i+=2,j++)
if (colType[j].equals("I"))
if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
psmt.setNull(j+1,java.sql.Types.NUMERIC);
else
psmt.setInt(j+1,Integer.parseInt(dataVector.elementAt(i).toString()));
else if (colType[j].equals("L"))
if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
psmt.setNull(j+1,java.sql.Types.NUMERIC);
else
psmt.setLong(j+1,Long.parseLong(dataVector.elementAt(i).toString()));
else if (colType[j].equals("F"))
if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
psmt.setNull(j+1,java.sql.Types.NUMERIC);
else
psmt.setFloat(j+1,Float.parseFloat(dataVector.elementAt(i).toString()));
else if (colType[j].equals("DB"))
if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
psmt.setNull(j+1,java.sql.Types.NUMERIC);
else
psmt.setDouble(j+1,Double.parseDouble(dataVector.elementAt(i).toString()));
else if (colType[j].equals("S"))
if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
psmt.setNull(j+1,java.sql.Types.VARCHAR);
else
psmt.setString(j+1,dataVector.elementAt(i).toString());
else if (colType[j].equals("D"))
if (dataVector.elementAt(i)==null||dataVector.elementAt(i).toString().equals(""))
psmt.setNull(j+1,java.sql.Types.DATE);
else
psmt.setString(j+1,dataVector.elementAt(i).toString());
int sucCnt = psmt.executeUpdate();
if (sucCnt > 0) sucFlag=true;
catch(Exception e)
return sucFlag;
/* Get Column Type of require table fields
tblNameString - Name of the table
return vector which contains the column types of the desired table
public Vector getColumnType(String tblNameString)
int colCount = 0;
String locString="";
Vector colVector = new Vector();
try
qryString = "select DATA_TYPE from user_tab_columns where table_name=? ORDER BY COLUMN_ID";
psmt = con.prepareStatement(qryString);
psmt.setString(1,tblNameString.toUpperCase());
rs = psmt.executeQuery();
while (rs.next())
colCount = rs.getMetaData().getColumnCount();
for(int i=1;i<=colCount;i++)
locString = rs.getString(i);
colVector.addElement(locString.equals("DATE")?"D":locString.equals("NUMBER")?"F":locString.equals("VARCHAR2")?"S":locString.equals("VARCHAR")?"S":"");
rs.close();
catch(Exception e)
return colVector;
/* update record
tblNameString - Name of the Table
dataVector - vector which contains the values according to the table order
eg., element(0) has first field, element(1) has second field vice versa
colType - String array contains type of all the fields.
return true - if record successfully updated
false - if Update fails
public boolean updateRecord(String tblNameString,Vector dataVector,String colType[],String whereString)
boolean sucFlag=false;
String fieldString=" ";
try
String commaString = "";
int fieldCount = dataVector.size();
for (int i=0;i<fieldCount-1;i++)
commaString +="?,";
commaString+="?";
if (fieldCount > 0)
String valueString[]= new String[fieldCount];
for (int i=0,j=0;i<fieldCount;i+=2,j++)
fieldString=fieldString+dataVector.elementAt(i)+"=?,";
valueString[j]=dataVector.elementAt(i+1).toString();
if (fieldString.substring(fieldString.length()-1,fieldString.length()).equals(","))
fieldString=fieldString.substring(0,fieldString.length()-1);
qryString = "update "+tblNameString+" set "+fieldString+" "+whereString;
psmt = con.prepareStatement(qryString);
for(int i=0,vectorPos=1;i<colType.length;i++,vectorPos+=2)
if (colType[i].equals("I"))
if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
psmt.setNull(i+1,java.sql.Types.NUMERIC);
else
psmt.setInt(i+1,Integer.parseInt(dataVector.elementAt(vectorPos).toString()));
else if (colType[i].equals("L"))
if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
psmt.setNull(i+1,java.sql.Types.NUMERIC);
else
psmt.setLong(i+1,Long.parseLong(dataVector.elementAt(vectorPos).toString()));
else if (colType[i].equals("F"))
if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
psmt.setNull(i+1,java.sql.Types.NUMERIC);
else
psmt.setFloat(i+1,Float.parseFloat(dataVector.elementAt(vectorPos).toString()));
else if (colType[i].equals("DB"))
if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
psmt.setNull(i+1,java.sql.Types.NUMERIC);
else
psmt.setDouble(i+1,Double.parseDouble(dataVector.elementAt(vectorPos).toString()));
else if (colType[i].equals("S"))
if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
psmt.setNull(i+1,java.sql.Types.VARCHAR);
else
psmt.setString(i+1,dataVector.elementAt(vectorPos).toString());
else if (colType[i].equals("D"))
if (dataVector.elementAt(vectorPos)==null||dataVector.elementAt(vectorPos).toString().equals(""))
psmt.setNull(i+1,java.sql.Types.DATE);
else
psmt.setString(i+1,dataVector.elementAt(vectorPos).toString());
int sucCnt = psmt.executeUpdate();
if (sucCnt > 0) sucFlag=true;
} // end of if
} // end of try
catch(Exception e)
return false;
return sucFlag;
public ResultSet getResultSet(String selectString)
try
stmt = con.createStatement();
rs = stmt.executeQuery(selectString);
catch(Exception e)
System.out.println(e.getMessage());
finally
return rs;
/* Get Query Result
selectString - Query
return the result vector based on the querystring
public Vector getResultVector(String selectString)
Vector resVector = new Vector();
try
stmt = con.createStatement();
rs = stmt.executeQuery(selectString);
while (rs.next())
resVector.addElement(rs.getString(1));
resVector.addElement(rs.getString(2));
catch(Exception e)
System.out.println(e.getMessage());
finally
return resVector;
/* return next consecutive number
tablenName - Name of the table for which the number to be generated
serialFiel - Name of the field for which the number to be generated
whereString - where condition to filter the records if composite key found,
it can be empty if there is no composite primary key.
startNumber - if there is no record exists in the table, set the starting number
public String getCurrentSerial(String tableName,String serialField,String whereString,String startNumber)
String queryString = "select max(to_number("+serialField+")) from "+tableName+" "+whereString;
int maxSerial=0;
try
psmt = con.prepareStatement(queryString);
rs = psmt.executeQuery();
while (rs.next())
maxSerial = rs.getInt(1);
if (maxSerial < 0)
maxSerial=Integer.parseInt(startNumber);
else
maxSerial+=1;
rs.close();
catch(Exception e)
return String.valueOf(maxSerial);
/* return next consecutive number
tablenName - Name of the table for which the number to be generated
serialFiel - Name of the field for which the number to be generated
whereString - where condition to filter the records if composite key found,
it can be empty if there is no composite primary key.
Note : if there is no record exists in the table, it starts with 1
public String getCurrentSerial(String tableName,String serialField,String whereString)
String queryString = "select max(to_number("+serialField+")) from "+tableName+" "+whereString;
int maxSerial=0;
try
stmt = con.createStatement();
rs = stmt.executeQuery(queryString);
while (rs.next())
maxSerial = rs.getInt(1);
if (maxSerial < 0)
maxSerial=1;
else
maxSerial+=1;
rs.close();
catch(Exception e)
System.out.println("Error from max serialX:"+e.getMessage());
return String.valueOf(maxSerial);
/* return the currnent user name */
public String getCurrentUser()
Statement stmt=null;
ResultSet rs=null;
String queryString = "select user from dual";
String userName = "";
try
stmt = con.createStatement();
rs = stmt.executeQuery(queryString);
while (rs.next())
userName = rs.getString(1);
rs.close();
catch(Exception e)
return userName;
/* return current user along with server's current date
example : userName#today
public String getCurrentUserDate()
Statement stmt=null;
ResultSet rs=null;
String queryString = "select user,to_char(sysdate,'dd-mon-yyyy') from dual";
String userName = "";
String todayDate= "";
try
stmt = con.createStatement();
rs = stmt.executeQuery(queryString);
while (rs.next())
userName = rs.getString(1);
todayDate = rs.getString(2);
rs.close();
catch(Exception e)
return userName+"#"+todayDate;
/* return server's current date */
public String getCurrentDate()
Statement stmt=null;
ResultSet rs=null;
String queryString = "select to_char(sysdate,'dd-mon-yyyy') from dual";
String todayDate= "";
try
stmt = con.createStatement();
rs = stmt.executeQuery(queryString);
while (rs.next())
todayDate = rs.getString(1);
rs.close();
catch(Exception e)
return todayDate;
/* return true if atleast one record found in the table
tblName : Name of the table
whereString : Where condition to filter the records
public boolean isRecordExists(String tblName,String whereString)
String queryString = "select count(1) from "+tblName+" "+whereString;
boolean recFound = false;
try
stmt = con.createStatement();
rs = stmt.executeQuery(queryString);
while (rs.next())
if (rs.getInt(1)==0)
recFound = false;
else
recFound = true;
rs.close();
catch(Exception e)
return recFound;
// round off decimal Places
public String fixDecimal(String sourceString,int digits)
String tmpText="",decimalPart="",returnText="";
try
sourceString = String.valueOf(Double.parseDouble(sourceString));
tmpText = sourceString.substring(sourceString.indexOf(".")+1);
if (tmpText.length() > digits)
decimalPart = tmpText.substring(0,digits);
if (Integer.parseInt(tmpText.substring(digits,digits+1))>=5)
decimalPart = String.valueOf(Integer.parseInt(decimalPart)+1);
tmpText = decimalPart;
if (decimalPart.length() > 3) // to check wheter 1000 reached, if yes add 1 to actual text
returnText = String.valueOf(Integer.parseInt(sourceString.substring(0,sourceString.indexOf(".")))+1);
else
returnText = sourceString.substring(0,sourceString.indexOf("."))+"."+tmpText;
else // if user entered decimal is with in 3 digits
if (tmpText.equals("0"))
returnText = sourceString.substring(0,sourceString.indexOf("."));
else
returnText = sourceString.substring(0,sourceString.indexOf("."))+"."+tmpText;
catch(Exception e)
System.out.println(e.getMessage());
return sourceString;
System.out.println(returnText);
return returnText;
} // end of main class
Access this Bean in JSP as follows:
<%@ page language="java" %>
<%@ page import="java.util.*"%>
<%@ include file="../connectionSetup.jsp"%>
<jsp:useBean id="dataBeanObj" class="id.dataBean"/>
<html>
<head>
<title>ADDRESS MASTER FORM</title>
<style type="text/css">
.tData
font-family : sans-serif;
font-size : 9px;
font-weight : bolder;
color : navy;
.buttonStyle
font-family : sans-serif;
font-size :10px;
</style>
</head>
<%
dataBeanObj.setConnection(con);
String curCode="";
String consFld = request.getParameter("consfld")==null?"":request.getParameter("consfld");
String cat = request.getParameter("cat")==null?"a":request.getParameter("cat").equals("a")?"a":"u";
boolean updateFlag=false,isWrongCountry=false;
String code="";
String name="";
String add1="";
String add2="";
String add3="";
String state="";
String country="";
String zip="";
String am_pcouncode="";
String am_pareacode="";
String am_psubcode="";
String am_fcouncode="";
String am_fareacode="";
String am_fsubcode="";
String am_phone="";
String am_fax="";
String email="";
String notes="";
String telex="";
String mobile="";
String popup="";
code = request.getParameter("code")==null?"":request.getParameter("code");
name = request.getParameter("name")==null?"":request.getParameter("name");
popup = request.getParameter("popup")==null?"":request.getParameter("popup");
String submitMode = request.getParameter("submit_mode")==null?"":request.getParameter("submit_mode");
String editMode = request.getParameter("edit_hidden")==null?"null":request.getParameter("edit_hidden");
if (name != null && !submitMode.equals("yes")) // ready to retrieve records
if (!code.equals(""))
rs = dataBeanObj.getResultSet("select am_code code,am_name name,am_address_1 add1,am_address_2 add2,am_address_3 add3,am_country country,am_state state,am_zip zip,am_phone phone,am_fax fax,am_e_mail email,am_notes notes,am_telex telex,am_mobile mobile from id_vms_address_master where am_code='"+code+"'");
else
rs = dataBeanObj.getResultSet("select am_code code,am_name name,am_address_1 add1,am_address_2 add2,am_address_3 add3,am_country country,am_state state,am_zip zip,am_phone phone,am_fax fax,am_e_mail email,am_notes notes,am_telex telex,am_mobile mobile from id_vms_address_master where upper(am_name)='"+name.toUpperCase()+"'");
if (rs.next()) // if record found
code = rs.getString("code"); // retrieve code
name = rs.getString("name"); // retrieve name
add1 = rs.getString("add1"); // retrieve address 1
add2 = rs.getString("add2"); // retrieve address 2
add3 = rs.getString("add3"); // retrieve address 3
country = rs.getString("country"); // retrieve country
state = rs.getString("state"); // retrieve state
zip = rs.getString("zip"); // retrieve zip
am_phone = rs.getString("phone"); // retrieve phone
am_fax = rs.getString("fax"); // retrieve fax
email = rs.getString("email"); // retrieve email
notes = rs.getString("notes"); // retrieve notes
telex = rs.getString("telex"); // retrieve telex number
mobile = rs.getString("mobile"); // retrieve mobile number
else if (submitMode.equals("yes")) // ready to submit
code = request.getParameter("code"); // get the input code
name = request.getParameter("name"); // get the input name
add1 = request.getParameter("address1"); // get the input address 1
add2 = request.getParameter("address2"); // get the input address 2
add3 = request.getParameter("address3"); // get the input address 3
country = request.getParameter("country"); // get the input country
state = request.getParameter("state"); // get the input state
zip = request.getParameter("zip"); // get the input zip
am_pcouncode = request.getParameter("pcouncode"); // get the input phone country code
am_pareacode = request.getParameter("pareacode"); // get the input phone area code
am_psubcode = request.getParameter("psubscode"); // get the input phone subscriber code
am_fcouncode = request.getParameter("fcouncode"); // get the input fax country code
am_fareacode = request.getParameter("fareacode"); // get the input fax area code
am_fsubcode = request.getParameter("fsubscode"); // get the input fax subscriber code
am_phone = am_pcouncode+"-"+am_pareacode+"-"+am_psubcode;
am_fax = am_fcouncode+"-"+am_fareacode+"-"+am_fsubcode;
telex = request.getParameter("telex"); // get the input telex
mobile = request.getParameter("mobile"); // get the input mobile
email = request.getParameter("email"); // get the input email
notes = request.getParameter("notes"); // get the input notes
String colType[] = {"S","S","S","S","S","S","S","S","S","S","S","S","S","S"};
Vector vec = new Vector();
if (cat.equals("u"))
vec.addElement("am_code"); vec.addElement(code); // add code to vector element
else
curCode = dataBeanObj.getCurrentSerial("id_vms_address_master","am_code","");
vec.addElement("am_code"); vec.addElement(curCode); // Next Serial Generation
vec.addElement("am_name"); vec.addElement(name); // add name to vector element
vec.addElement("am_address_1"); vec.addElement(add1); // add address 1 to vector element
vec.addElement("am_address_2"); vec.addElement(add2); // add address 2 to vector element
vec.addElement("am_address_3"); vec.addElement(add3); // add address 3 to vector element
vec.addElement("am_country"); vec.addElement(country); // add country to vector element
vec.addElement("am_state"); vec.addElement(state); // add state to vector element
vec.addElement("am_zip"); vec.addElement(zip); // add zip to vector element
vec.addElement("am_phone"); vec.addElement(am_phone); // add phone to vector element
vec.addElement("am_fax"); vec.addElement(am_fax); // add fax to vector element
vec.addElement("am_e_mail"); vec.addElement(email); // add email to vector element
vec.addElement("am_notes"); vec.addElement(notes); // add notes to vector element
vec.addElement("am_telex"); vec.addElement(telex); // add telex to vector element
vec.addElement("am_mobile"); vec.addElement(mobile); // add mobile to vector element
if (dataBeanObj.isRecordExists("id_country_master"," where country_code='"+country+"'"))
if (cat.equals("u"))
// update the records
updateFlag = dataBeanObj.updateRecord("id_vms_address_master",vec,colType,"where am_code='"+code+"'");
else
// insert record
updateFlag = dataBeanObj.insertRecordPart("id_vms_address_master",vec,colType);
else
isWrongCountry=true;
%>
The connectionSetup.jsp is as follows:
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.naming.*" %>
<%@ page import="allaire.taglib.*" %>
<%
Connection con=null;
PreparedStatement ps = null;
Statement stmt=null;
ResultSet rs=null;
try
String jrunDSN = null, lookupDSN = null;
jrunDSN = request.getParameter("dsnvalue") == null ? "vms_test" : request.getParameter("dsnvalue");
lookupDSN = "java:comp/env/jdbc/" + jrunDSN;
InitialContext ctx = new InitialContext();
DataSource dsn = (DataSource)ctx.lookup(lookupDSN);
try
if (application.getAttribute("connectionapplication") == null)
con = dsn.getConnection();
application.setAttribute("connectionapplication",con);
else
con = (Connection) application.getAttribute("connectionapplication");
stmt = con.createStatement();
catch(Exception e)
con = dsn.getConnection();
application.setAttribute("connectionapplication",con);
catch(Exception e)
out.println("<font face='arial' size='2'><center>Problem with database connection. Please contact your administrator</center></font>");
%>
In Connection setup.jsp u can change as u need.
This is thru JNDI. This works fine for us in our projects.
Bye. -
Command the execute sql query and does not clean up data in Table
Hi Team
I have an SP, which writes source and target data to Temp Tables and runs except query to get mismatch details
I am using Exec command to execute source query that writes data to Temp Table, once I execute query using Exec, data is written and immediately #temp table is cleaned, now I cannot use #temp table for comparition.
Is there any way to execute sql query in SP without using EXEC and will hold the data in temp table.You need to create temp table before EXEC statement and rewrite your dynamic query also as below
declare @source_Sql nvarchar(1000)
,@target_Sql nvarchar(1000)
create table #TempTable1 (name nvarchar(10))
create table #TempTable2 (name nvarchar(10))
set @source_Sql = 'INSERT INTO #TempTable1 SELECT [Name] from Employee'
set @target_Sql = 'INSERT INTO #TempTable2 SELECT [Name] from Employee2'
EXEC (@source_Sql)
EXEC (@target_Sql)
select * from #TempTable1
Except
select * from #TempTable2 -
Select type_address in Portal report's sql query using remote database
how do i select type_address item from remote database table ?
I've already create the database link called db_link.
I've already execute the sql statement in the specified database, and it works.
for example: ( sql plus in the specified database )
select syk.alamat_syarikat.alamat1 from MCS_SYARIKAT syk
for example: ( sql statement in portal report using database link )
select nama_syarikat, syk.alamat_syarikat.alamat1 from MCS_SYARIKAT@dblink syk
error massage:
Unable to describe SQL statement. Please correct it (WWV-13010)
Invalid SQL statement: select syk.alamat_syarikat.alamat1 from MCS_SYARIKAT@dblink syk (WWV-13005)
ORA-01001: invalid cursor (WWV-11230)
ORA-22804: remote operations not permitted on object tables or user-defined type columns (WWV-11230)
Failed to parse as MCS_PUBLIC - select syk.alamat_syarikat.alamat1 from MCS_SYARIKAT@dblink syk (WWV-08300)Here's the actual query:
SELECT BUILD_EXT_RES_LIST(EXT_FILE.ID) A
FROM EXT_FILE_RES, EXT_FILE
WHERE EXT_FILE_RES.ON_OWNER_PROFILE = 'Y' AND
EXT_FILE.OWNER_ID = :PROFILE AND
EXT_FILE.ID = EXT_FILE_RES.EXT_ID AND
(RES_SUBSCRIBER_YN(EXT_FILE.ID,:CURR_ID) = 'YES' OR
ADMINYESNO(:CURR_ID,:PROFILE) = 'YES')
ORDER BY EXT_FILE.FILE_NAMEAnd here's the actual error message:
1 error has occurred
Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the ''generic columns'' checkbox below the region source to proceed without parsing. ORA-00904: "SER_IS_ADMINYESNO": invalid identifier -
OutOfMemory error while executing sql query
Hello!
My program gets multiple datas from database in every ten minutes, and stores them in memory for hundreds of users, requesting datas via web-interface simoultaneously.
I dont have access to change database structures, write stored procedures, etc, just read from db.
There is a table in database with lot of million rows, and sometimes when I try to execute a SELECT on this table it takes minutes to get back the result.
To avoid waiting for database server for a long time, I set querytimeout to 30 seconds.
If the server throws back the execution with Query Timed out Exception, I want to 'forget' this data, and 0 value is acceptable because of fast run is more important. So I put the boolean broken variable to check if there is any problem with db server.
The size of the used memory is about 150Mb if things going well, but I set the max heap to 512 MB, just in case anything happens.
I'm logging all threads stacktrace, and free/used/allocated memory size in every 5 seconds.(threadwatching.log) 2.appendix
Sometimes, not in every case (I dont know what is this depends on), when I get the next phase of refreshing cached datas (you can see it below), the process reaches the fiorst checkpoint (signed in code below), starts to execute the sql query, and never reaches the second checkpoint , but used memory growing 50-60 Mb-os in every 5 seconds, as I can see in threadwatching.log until it reaches the max memory and throws OutOfMemory error: java heap space.
I'm using DbConnectionBroker for connection pooling, SQLCommandBean for handling Statements, PreparedStatements, etc, and jTDS jdbc connector.
SQLCommandBean closes statements, resultsets, so these objects doesnt stays open.
I cant figured out what causes the memory leak, if someone have an idea, please help me.
1. Part of the cached data refreshing (DataFactory.createPCVPPMforSiemens()):
PCVElement element = new PCVElement(m, ProcessControlView.PPM);
String s = DateTime.getDate(interval.getStartDate());
boolean broken=false;
int value = 0;
for (int j = 0; j < 48; j++) {
try {
if (!broken) {
d1 = DateTime.getDate(new Date(start + ((j + 1) * 600000)));
sqlBean = new SQLCommandBean();
conn = broker.getConnection();
sqlBean.setConnection(conn);
sqlBean.setQueryTimeOut(30);
System.out.println(DateTime.getDate(new Date())+" "+m.getName()+" "+j);// first checkpoint
value = SiemensWorks.getPCVPPM(sqlBean, statId, s, d1);
System.out.println(DateTime.getDate(new Date())+" "+m.getName()+" "+j);// second checkpoint
} else value=0;
} catch (Exception ex) {
System.out.println("ERROR: DataFactory.createPCVPPMforSiemens 1 :" + ex.getMessage());
ex.printStackTrace();
value = 0;
broken=true;
} finally {
try {
broker.freeConnection(conn);
} catch (Exception ex) {}
element.getAvgValues()[j] = value;
}2. SiemensWorks.getPCVPPM()
public static int getPCVPPM(SQLCommandBean sqlBean,int statID,String start,String end)
throws SQLException, UnsupportedTypeException, NoSuchColumnException {
sqlBean.setSqlValue(SiemensSQL.PCV_PPM);
Vector values=new Vector();
values.add(new StringValue(statID+""));
values.add(new StringValue(start));
values.add(new StringValue(end));
sqlBean.setValues(values);
Vector rows=sqlBean.executeQuery();
if (rows==null || rows.size()==0) return 0;
Row row=(Row)rows.firstElement();
try {
float ret=Float.parseFloat(row.getString(1));
if (ret<=0) ret=0;
return Math.round(ret);
} catch (Exception ex) {
return 0;
}3. Part of Threadwatching.log
2006-10-13 16:46:56 Name: SMT Refreshing Threads
2006-10-13 16:46:56 Thread count: 4
2006-10-13 16:46:56 Active count: 4
2006-10-13 16:46:56 Active group count: 0
2006-10-13 16:46:56 Daemon: false
2006-10-13 16:46:56 Priority: 5
2006-10-13 16:46:57 Free memory: 192,228,944 bytes
2006-10-13 16:46:57 Max memory: 332,988,416 bytes
2006-10-13 16:46:57 Memory in use: 140,759,472 bytes
2006-10-13 16:46:57 ---------------------------------
2006-10-13 16:46:57 0. Name: CachedLayerTimer
2006-10-13 16:46:57 0. Id: 19
2006-10-13 16:46:57 0. Priority: 5
2006-10-13 16:46:57 0. Parent: SMT Refreshing Threads
2006-10-13 16:46:57 0. State: RUNNABLE
2006-10-13 16:46:57 0. Alive: true
2006-10-13 16:46:57 java.io.FileOutputStream.close0(Native Method)
2006-10-13 16:46:57 java.io.FileOutputStream.close(Unknown Source)
2006-10-13 16:46:57 sun.nio.cs.StreamEncoder$CharsetSE.implClose(Unknown Source)
2006-10-13 16:46:57 sun.nio.cs.StreamEncoder.close(Unknown Source)
2006-10-13 16:46:57 java.io.OutputStreamWriter.close(Unknown Source)
2006-10-13 16:46:57 xcompany.smtmonitor.chart.ChartCreator.createChart(ChartCreator.java:663)
2006-10-13 16:46:57 xcompany.smtmonitor.chart.ChartCreator.create(ChartCreator.java:441)
2006-10-13 16:46:57 xcompany.smtmonitor.CachedLayerRefreshenerTask.run(CachedLayerRefreshenerTask.java:463)
2006-10-13 16:46:57 java.util.TimerThread.mainLoop(Unknown Source)
2006-10-13 16:46:57 java.util.TimerThread.run(Unknown Source)
Software runs well until I get the DataFactory.createPCVPPMforSiemens function in my code ->
2006-10-13 16:47:01 Name: SMT Refreshing Threads
2006-10-13 16:47:01 Thread count: 4
2006-10-13 16:47:01 Active count: 4
2006-10-13 16:47:01 Active group count: 0
2006-10-13 16:47:01 Daemon: false
2006-10-13 16:47:01 Priority: 5
2006-10-13 16:47:02 Free memory: 189,253,304 bytes
2006-10-13 16:47:02 Max memory: 332,988,416 bytes
2006-10-13 16:47:02 Memory in use: 143,735,112 bytes
2006-10-13 16:47:02 ---------------------------------
2006-10-13 16:47:02 0. Name: CachedLayerTimer
2006-10-13 16:47:02 0. Id: 19
2006-10-13 16:47:02 0. Priority: 5
2006-10-13 16:47:02 0. Parent: SMT Refreshing Threads
2006-10-13 16:47:02 0. State: RUNNABLE
2006-10-13 16:47:02 0. Alive: true
2006-10-13 16:47:02 java.util.LinkedList$ListItr.previous(Unknown Source)
2006-10-13 16:47:02 net.sourceforge.jtds.util.TimerThread.setTimer(TimerThread.java:174)
2006-10-13 16:47:02 net.sourceforge.jtds.jdbc.TdsCore.wait(TdsCore.java:3734)
2006-10-13 16:47:02 net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:997)
2006-10-13 16:47:02 net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:320)
2006-10-13 16:47:02 net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:667)
2006-10-13 16:47:02 xcompany.database.sql.SQLCommandBean.executeQuery(SQLCommandBean.java:91)
2006-10-13 16:47:02 xcompany.smtmonitor.data.SiemensWorks.getPCVPPM(SiemensWorks.java:409)
2006-10-13 16:47:02 xcompany.smtmonitor.data.DataFactory.createPCVPPMforSiemens(DataFactory.java:6103)
2006-10-13 16:47:02 xcompany.smtmonitor.data.DataFactory.refreshProcessControlView(DataFactory.java:5791)
2006-10-13 16:47:02 xcompany.smtmonitor.CachedLayerRefreshenerTask.run(CachedLayerRefreshenerTask.java:514)
2006-10-13 16:47:02 java.util.TimerThread.mainLoop(Unknown Source)
2006-10-13 16:47:02 java.util.TimerThread.run(Unknown Source)
2006-10-13 16:47:06 Name: SMT Refreshing Threads
2006-10-13 16:47:06 Thread count: 4
2006-10-13 16:47:06 Active count: 4
2006-10-13 16:47:06 Active group count: 0
2006-10-13 16:47:06 Daemon: false
2006-10-13 16:47:06 Priority: 5
2006-10-13 16:47:08 Free memory: 127,428,192 bytes
2006-10-13 16:47:08 Max memory: 332,988,416 bytes
2006-10-13 16:47:08 Memory in use: 205,560,224 bytes
2006-10-13 16:47:08 ---------------------------------
2006-10-13 16:47:08 0. Name: CachedLayerTimer
2006-10-13 16:47:08 0. Id: 19
2006-10-13 16:47:08 0. Priority: 5
2006-10-13 16:47:08 0. Parent: SMT Refreshing Threads
2006-10-13 16:47:08 0. State: RUNNABLE
2006-10-13 16:47:08 0. Alive: true
2006-10-13 16:47:08 java.util.LinkedList$ListItr.previous(Unknown Source)
2006-10-13 16:47:08 net.sourceforge.jtds.util.TimerThread.setTimer(TimerThread.java:174)
2006-10-13 16:47:08 net.sourceforge.jtds.jdbc.TdsCore.wait(TdsCore.java:3734)
2006-10-13 16:47:08 net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:997)
2006-10-13 16:47:08 net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:320)
2006-10-13 16:47:08 net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:667)
2006-10-13 16:47:08 xcompany.database.sql.SQLCommandBean.executeQuery(SQLCommandBean.java:91)
2006-10-13 16:47:08 xcompany.smtmonitor.data.SiemensWorks.getPCVPPM(SiemensWorks.java:409)
2006-10-13 16:47:08 xcompany.smtmonitor.data.DataFactory.createPCVPPMforSiemens(DataFactory.java:6103)
2006-10-13 16:47:08 xcompany.smtmonitor.data.DataFactory.refreshProcessControlView(DataFactory.java:5791)
2006-10-13 16:47:08 xcompany.smtmonitor.CachedLayerRefreshenerTask.run(CachedLayerRefreshenerTask.java:514)
2006-10-13 16:47:08 java.util.TimerThread.mainLoop(Unknown Source)
2006-10-13 16:47:08 java.util.TimerThread.run(Unknown Source)
2006-10-13 16:47:12 Name: SMT Refreshing Threads
2006-10-13 16:47:12 Thread count: 4
2006-10-13 16:47:12 Active count: 4
2006-10-13 16:47:12 Active group count: 0
2006-10-13 16:47:12 Daemon: false
2006-10-13 16:47:12 Priority: 5
2006-10-13 16:47:15 Free memory: 66,760,208 bytes
2006-10-13 16:47:15 Max memory: 332,988,416 bytes
2006-10-13 16:47:15 Memory in use: 266,228,208 bytes
2006-10-13 16:47:15 ---------------------------------
2006-10-13 16:47:15 0. Name: CachedLayerTimer
2006-10-13 16:47:15 0. Id: 19
2006-10-13 16:47:15 0. Priority: 5
2006-10-13 16:47:15 0. Parent: SMT Refreshing Threads
2006-10-13 16:47:15 0. State: RUNNABLE
2006-10-13 16:47:15 0. Alive: true
2006-10-13 16:47:15 java.util.LinkedList.addBefore(Unknown Source)
2006-10-13 16:47:15 java.util.LinkedList.access$300(Unknown Source)
2006-10-13 16:47:15 java.util.LinkedList$ListItr.add(Unknown Source)
2006-10-13 16:47:15 net.sourceforge.jtds.util.TimerThread.setTimer(TimerThread.java:175)
2006-10-13 16:47:15 net.sourceforge.jtds.jdbc.TdsCore.wait(TdsCore.java:3734)
2006-10-13 16:47:15 net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:997)
2006-10-13 16:47:15 net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:320)
2006-10-13 16:47:15 net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:667)
2006-10-13 16:47:15 xcompany.database.sql.SQLCommandBean.executeQuery(SQLCommandBean.java:91)
2006-10-13 16:47:15 xcompany.smtmonitor.data.SiemensWorks.getPCVPPM(SiemensWorks.java:409)
2006-10-13 16:47:15 xcompany.smtmonitor.data.DataFactory.createPCVPPMforSiemens(DataFactory.java:6103)
2006-10-13 16:47:15 xcompany.smtmonitor.data.DataFactory.refreshProcessControlView(DataFactory.java:5791)
2006-10-13 16:47:15 xcompany.smtmonitor.CachedLayerRefreshenerTask.run(CachedLayerRefreshenerTask.java:514)
2006-10-13 16:47:15 java.util.TimerThread.mainLoop(Unknown Source)
2006-10-13 16:47:15 java.util.TimerThread.run(Unknown Source)
2006-10-13 16:47:17 Name: SMT Refreshing Threads
2006-10-13 16:47:17 Thread count: 4
2006-10-13 16:47:17 Active count: 4
2006-10-13 16:47:17 Active group count: 0
2006-10-13 16:47:17 Daemon: false
2006-10-13 16:47:17 Priority: 5
2006-10-13 16:47:20 Free memory: 23,232,496 bytes
2006-10-13 16:47:20 Max memory: 332,988,416 bytes
2006-10-13 16:47:20 Memory in use: 309,755,920 bytes
2006-10-13 16:47:20 ---------------------------------
2006-10-13 16:47:20 0. Name: CachedLayerTimer
2006-10-13 16:47:20 0. Id: 19
2006-10-13 16:47:20 0. Priority: 5
2006-10-13 16:47:20 0. Parent: SMT Refreshing Threads
2006-10-13 16:47:20 0. State: RUNNABLE
2006-10-13 16:47:20 0. Alive: true
2006-10-13 16:47:20 net.sourceforge.jtds.util.TimerThread.setTimer(TimerThread.java:171)
2006-10-13 16:47:20 net.sourceforge.jtds.jdbc.TdsCore.wait(TdsCore.java:3734)
2006-10-13 16:47:20 net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:997)
2006-10-13 16:47:20 net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:320)
2006-10-13 16:47:20 net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:667)
2006-10-13 16:47:20 xcompany.database.sql.SQLCommandBean.executeQuery(SQLCommandBean.java:91)
2006-10-13 16:47:20 xcompany.smtmonitor.data.SiemensWorks.getPCVPPM(SiemensWorks.java:409)
2006-10-13 16:47:20 xcompany.smtmonitor.data.DataFactory.createPCVPPMforSiemens(DataFactory.java:6103)
2006-10-13 16:47:20 xcompany.smtmonitor.data.DataFactory.refreshProcessControlView(DataFactory.java:5791)
2006-10-13 16:47:20 xcompany.smtmonitor.CachedLayerRefreshenerTask.run(CachedLayerRefreshenerTask.java:514)
2006-10-13 16:47:20 java.util.TimerThread.mainLoop(Unknown Source)
2006-10-13 16:47:20 java.util.TimerThread.run(Unknown Source)
2006-10-13 16:47:23 Name: SMT Refreshing Threads
2006-10-13 16:47:23 Thread count: 4
2006-10-13 16:47:23 Active count: 4
2006-10-13 16:47:23 Active group count: 0
2006-10-13 16:47:23 Daemon: false
2006-10-13 16:47:23 Priority: 5
2006-10-13 16:47:26 Free memory: 4,907,336 bytes
2006-10-13 16:47:26 Max memory: 332,988,416 bytes
2006-10-13 16:47:26 Memory in use: 328,083,768 bytes
2006-10-13 16:47:26 ---------------------------------
2006-10-13 16:47:26 0. Name: CachedLayerTimer
2006-10-13 16:47:26 0. Id: 19
2006-10-13 16:47:26 0. Priority: 5
2006-10-13 16:47:26 0. Parent: SMT Refreshing Threads
2006-10-13 16:47:26 0. State: RUNNABLE
2006-10-13 16:47:26 0. Alive: true
2006-10-13 16:47:26 java.util.LinkedList.addBefore(Unknown Source)
2006-10-13 16:47:26 java.util.LinkedList.access$300(Unknown Source)
2006-10-13 16:47:26 java.util.LinkedList$ListItr.add(Unknown Source)
2006-10-13 16:47:26 net.sourceforge.jtds.util.TimerThread.setTimer(TimerThread.java:175)
2006-10-13 16:47:26 net.sourceforge.jtds.jdbc.TdsCore.wait(TdsCore.java:3734)
2006-10-13 16:47:26 net.sourceforge.jtds.jdbc.TdsCore.executeSQL(TdsCore.java:997)
2006-10-13 16:47:26 net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:320)
2006-10-13 16:47:26 net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:667)
2006-10-13 16:47:26 xcompany.database.sql.SQLCommandBean.executeQuery(SQLCommandBean.java:91)
2006-10-13 16:47:26 xcompany.smtmonitor.data.SiemensWorks.getPCVPPM(SiemensWorks.java:409)
2006-10-13 16:47:26 xcompany.smtmonitor.data.DataFactory.createPCVPPMforSiemens(DataFactory.java:6103)
2006-10-13 16:47:26 xcompany.smtmonitor.data.DataFactory.refreshProcessControlView(DataFactory.java:5791)
2006-10-13 16:47:26 xcompany.smtmonitor.CachedLayerRefreshenerTask.run(CachedLayerRefreshenerTask.java:514)
2006-10-13 16:47:26 java.util.TimerThread.mainLoop(Unknown Source)
2006-10-13 16:47:26 java.util.TimerThread.run(Unknown Source)
2006-10-13 16:47:35 Name: SMT Refreshing Threads
2006-10-13 16:47:37 Thread count: 4
2006-10-13 16:47:38 Active count: 4
2006-10-13 16:47:38 Active group count: 0
2006-10-13 16:47:38 Daemon: false
2006-10-13 16:47:38 Priority: 5
2006-10-13 16:47:42 Free memory: 35,316,120 bytes
2006-10-13 16:47:42 Max memory: 332,988,416 bytes
2006-10-13 16:47:42 Memory in use: 297,672,296 bytes
2006-10-13 16:47:42 ---------------------------------
2006-10-13 16:47:42 0. Name: CachedLayerTimer
2006-10-13 16:47:42 0. Id: 19
2006-10-13 16:47:42 0. Priority: 5
2006-10-13 16:47:42 0. Parent: SMT Refreshing Threads
2006-10-13 16:47:42 0. State: TIMED_WAITING
2006-10-13 16:47:42 0. Alive: true
2006-10-13 16:47:42 java.lang.Object.wait(Native Method)
2006-10-13 16:47:42 java.util.TimerThread.mainLoop(Unknown Source)
2006-10-13 16:47:42 java.util.TimerThread.run(Unknown Source)
4. Tomcat default logging file:
2006-10-13 16:47:36 ERROR CachedLayerRefreshenerTask: external error: Java heap space
5. DbConnectionBroker (connection pooling) logging file:
Handing out connection 1 --> 10/13/2006 04:47:01 PM
Handing out connection 0 --> 10/13/2006 04:47:01 PM
Handing out connection 1 --> 10/13/2006 04:47:01 PM
Handing out connection 0 --> 10/13/2006 04:47:02 PM
Warning. Connection 0 in use for 3141 ms
Warning. Connection 0 in use for 24891 ms
----> Error: Could not free connection!!!
I would appreciate for any help.What does your query bring back from this table?This is the query:
SELECT case sum(c.picked) when 0 then 0 else
((sum(c.picked)-(sum(c.picked)-(sum(c.vacuum)+sum(c.id
ent))))*cast((1000000/cast(sum(c.picked) as float))
as bigint)) end as PPM
FROM sip_comp c
LEFT JOIN sip_pcb pc ON pc.id=c.pcbid
LEFT JOIN sip_period p on p.id=pc.periodid
WHERE p.stationid=? AND pc.time BETWEEN ? AND ?Has anybody who knows SQL tried EXPLAIN PLAN to optimize this table? You're joining on a table with a million rows and you're wondering why the performance is poor?
What is the index situation with these tables?
.> When I execute it from query manager, it takes from 1
to 60 secs depend on servers availability. So how will that be any different for JDBC and Java?
..> You're right. Thats why I am here.
What I mean by that is we can't read minds, either. You need to get some hard data to tell you where the bottleneck is. Asking at a forum won't help.
But tell me, if the java process enters to this query
execution, and doesnt quit until OOM thrown, how can
be the problem in caching?I was guessing about caching, because I didn't know what the query was.
You expect a lot.
.> No.
Then how do you ever expect to solve this?
I tried YourKit Profiler at home, where I'm
developing software, but this OOM never thrown here,
even if I have the same database size.Then you aren't replicating the problem. You have to run it on the system that has the problem if you're going to solve it.
YourKit isn't an industry leader. How well do you know how to use it?
It just happened at the company where the system
runs, and I cannot run this profiler there because
the PC where my tomcat runs dramatically slowed.You have to run something to figure out what the problem is. What about Log4J, some trace logging statements and a batch job to harvest the log?
Bottom line: you've got to be a scientist and get some real data. We can theorize all we want here, but that won't get you to a solution.
% -
Help needed in executing SQL query...
Hi,
I am very new to JDeveloper. Curently i am tryin to execute an SQL query from the BPEL process, the output of the query is to be mapped to a variable field from a target xsd file. the query is fairly simple, like
SELECT emp
FROM emp_table
WHERE emp_id=123
The target field, namely "employee", is an element from the xsd file. I tried using Java embedding activity to connect to the db and execute the query through a piece of Java code, but couldn't find a way to assign the output of the query to the field. however lately i also discovered the Database Adapter services which helps me create a database connection, but still i am not sure as of how to handle and map the output of the query to the variable field.
Can somebody please help me in resolving the issue either through Java Embed activity or Database Adapter services??
Thanks in advance
AnjanAnjan,
I suggest you try the [url http://forums.oracle.com/forums/forum.jspa?forumID=212]BPEL Forum
John -
Store SQL Query in Oracle database
Hello,
I am storing SQL query in database. here is an example of query.
INSERT INTO TABLE_1 Values (' " + getValue1() + " ', ' " + getValue2() + " ' )
getValue1() and getValue2() are functions to retrieve values.
When I read query from the database and execute it, it doesn't read values from function.
After I read query from database I would expect it to be
INSERT INTO TABLE_1 Values ('value1', ' value2' ) but it is not reading values and trying to execute whatever I got from database.
Any help?
ThanksThanks for your reply. Let me give you more info.
All I am trying to do is storing queries in oracle
database to use it in future for reporting. As I am
doing reporting where clause will be different every
time. Reporting involves queries not updates. But in any case that means that you would use a java SQL string that is useable via a prepared statement. As such your statement would look like....
INSERT INTO TABLE_1 Values (?,?)
Is it not possible to substitute variable string I
got from database?What do you mean?
SQL is SQL. You construct SQL so it is valid and runs. Can you construct SQL so it runs a function/select and uses that value in some more SQL - depends on the database, but usually.
But that has nothing to do with java - it is SQL.
Query contains variables that I have in Java code .Then it is SQL. It is java. You use bind variables (see PreparedStatement) and assign values to it.
The SQL for such a query would look like the following...
select field1, field2 from table1 where id=?
In your java you would then use something like PreparedStatement.setInt(1, 100), to fill in the value for the '?' in the above.
You might also note that your solution will not work for any arbritrary SQL statement unless you are also storing meta data about the SQL itself. For instance the following SQL statements would return the same result set but your java code would have to populate the bind variables different for both...
select field1, field2 from table1 where id=? and name=?
select field1, field2 from table1 where name=? and id=? -
Executing sql query in maviewer 10.1.3 javascript api
Hi, i want to execute a sql query according to my applications requirement i.e. for retrieving some fields from the oracle database.How to do that? Please someone help me. Thanks.
Im sorry..
But how can I use JSP for querying non spatial data???
Can you give me some example please..
I've read about doQuery.. but I don't quite understand how to use it.. ^^ -
Same sql query with multiple database links
Hi All,
i want to execute an sql query for a SELECT LIST Item. which should use database links in it's query.
i'm having a list of database links in the region. say :LOC which is having 10 items each linking to different databases.
i want to use following query for another item in same page.
select customer_name from working_lines@:LOC where
phone_no:phone_no
can i do this.
Thank you All.What we have done before is to create a report based on a PL/SQL procedure that returns a SQL statement.
The PL/SQL code grabs the "selected" database link from :LOC and parses the SQL QUERY you want to execute replacing some token (like [LINK]) with '@DBNAME'.
Lets say your SQL statement is coded like this:
mySQL := 'SELECT cust_name FROM working_lines[LINK] where phone_no = :Phone;'
Then all you would have to do to replace '[LINK]' with the proper DB alias would be:
mySQL := REPLACE(mySQL, '[LINK]', '@'||:LOC);
and then return the new SQL ...
if :LOC has something like 'V10GPROD' your SQL would look like :
SELECT cust_name FROM working_lines@V10GPROD where phone_no = :Phone;
The beauty of this is that you can also include a "null" option that means the select statement will be executed on THIS database...
Doug -
How to set fetchsize of sql Query when using Database Adapter.
Hi All,
I am using DatabaseAdapter to connect to database and retriving huge amount of data.For improvement in the performance I want to set the "fetchsize" of sql query. I know fetchsize can be preset in Java using Jdbc 2.0 API.Please let me know how to set this value in BPEL when using DBAdapter?
Thanks
ChandraI talked to the developer of the db adapter - and he told me this feature will be available in BPEL PM 10.1.3 (which is supposed to be production later this year, and a public beta soon). If this is an emergency I would recommend going throug Oracle support and have them file an enhancement for 10.1.2.0.2
hth clemens -
How to Execute sql query in PL/SQL ( a variable) with out using Cursor or REF cursor
Hi
I am building a dynamic query based on some conditions
as an example
v_query varchar2(2000);
x1 varchar2(20);
y1 varchar2(20);
z1 varchar2(20);
v_query := ' Select x,y,z into x1,y1,z1 From ... ';
Is there any way to execute the query with out using cursor or ref cursor..
Thanks
ArunBoth Tod and Eric provided valid responses given the format of the queory you supplied. Howver, if you want to use dynamic sql in either way, you need to be absolutely certain that your query will always only return a single row (e.g. SELECT COUNT(*) FROM mytable), because if it retuns more than one, your procedure will break unless you have an exception handler to handle either TOO_MANY_ROWS or OTHERS.
If you want to pull in a lot of data without walking a cursor, you should look at the BULK COLLECT options. -
Problem in SQL query in MDB database
Hello all,
I am using mdb database and want to read specific time stamp record based on time stamp. I am using simple sql query but I am getting one error. Please let me know where I am making mistake(s). One error is operator missing. VI and database is attached.
My query is -SELECT * FROM Downloaded_120 where col2 between 13:00:00 04-06-2013 and 14:00:00 04-06-2013
Thanks.
Kudos are always welcome if you got solution to some extent.
I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
Attachments:
VI and database.zip 372 KBhttp://digital.ni.com/public.nsf/allkb/4012B21BA0876907862576110070FC0A
You're missing the #s, too.
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
Maybe you are looking for
-
Not allowed to access the "name" of my Apple ID under Seettings in IOS 7.0.4
Until this past week, I had used an Apple Iphone 4S. Recently, I purchased my son an Iphone as well. I initially upgraded his TMobile account to the 5S for me and gave my old Verizon IPhone to him. It didn't work out but I did learn that I preferr
-
The installation of FMS 3.5.1 r516 Development fatally failed on our Windows 2008 R2 Server. We tried an R1 server and that one installed with no issues. It gets past the MS C++ installer, then shortly after: Problem signature: Problem Event Name:
-
I think with the work being put forth by Last.fm, Pandora and the music genome project that itunes should be able to scan my music library and make suggestions in the mini store about what i may like. If the itunes music store is a great way to disco
-
Selecting more than one calendar but not all?
is it possible on the iTouch iCal application to view more than one calendar but not all? I have one calendar that I would like to have available, but when I check for conflicts, that calendar doesn't matter (if it were included, every day would be a
-
Aperture, versions unavailable masters
Greetings, What I have done.. It has been a while working with aperture. I started to reorganize my photos after a couple of years. I had a library saved on an external hard-disk and I opened it. But I'm not able to export the photos. This is in the