How to Get SQL Results in Java?
Hello,
I'm new to java and have a few questions when running sql. I have no problems connecting to the Oracle 9i database, but my questions are these:
(1) I have a CREATE TABLE statement. How do I check to see if the table was actually created? SQL returns the statement "table created" if it was successful. I've tried different "out.print(resultSet.*" statements to return either success or failure, but nothing is working.
(2) I created a measure called sqlQuery. Can I put multiple sql statements in this measure? How do I get a resultSet for each sql statement and not just the last one?
(3) Is it possible to use the * (i.e., select * from tablename) in Java? I've tried this unsuccessfully too.
Many thanks
Start with this:
http://java.sun.com/javase/technologies/database/
%
Similar Messages
-
How to get query result in comma dilimited text or excel file?
Does anybody know how to get query results in comma delimited
text file or excel file, I tried spool abc.txt, but the result
showed some ------ lines
ThanksTry doing this in your sql scripts
set heading off
set pagesize 0
set linesize 4000
set feedback off
set verify off
set trimespace on
set colsep ","
spool output.txt
select * from dual (or whatever you are querying
spool off
There may be a couple other set statement that you could add but
this should get you started in the right direction -
How to use sql query in java ?
i don't know how to use sql query in java code.
who can give me some advice?
thankshttp://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/
-
Call function in background task... How to get the result?
I want to use Call function in background task parameter.
But I cannot find the result of this function. (No export parameter, no table result, no exception)
How to get the result of this function module? Correct or not?Hi Heinz,
You can check the result in SM58 transaction.
For more information pls. refer this thread :
No IMPORTING parameters allowed in CALL FUNCTION IN BACKGROUND TASK
Best regards,
Prashant -
Af:query - How to get the result rowsets
Hi,
I have a requirement where i need to search the db rows on and append the results the adf rich table on each search.
For this i am using af:query component. And trying to get the result rows for the named criteria.
String mexpr = "#{bindings.DestinDescVOCriteriaQuery.processQuery}";
processMethodExpression(mexpr, queryEvent, QueryEvent.class);
ViewCriteriaManager vcm = getDestinDescViewObj().getViewCriteriaManager();
ViewCriteria vc = vcm.getViewCriteria("DestinDescVOCriteria");
getDestinDescViewObj().applyViewCriteria(vc);
AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
adfFacesContext.addPartialTarget(tblDestinDesc);
However on each click of search the rows searched in the previous attempt are not retained.
Can anyone let me know how to get the result from named criteria and append it the table?
Thanks
AjayCan anyone help?
-
how can i do with labview program,when i have 20 different values,and 1 want to add it with constant value.and how to get the results?
Why do the 20 values have to be different? The same code should work even if some are equal.
What do you mean by "get the result"? The result is available at the output terminal and all you need is a wire to get it where you need it. That could be an indicator, another operation, or even a hardware device.
What is the data type of the 20 values? An array? A cluster? A bunch of scalars? A waveform? Dynamic data?
LabVIEW Champion . Do more with less code and in less time . -
How to get the results for given Bind Variable
Hi
Can any one help me how to get the result rows from the View Object after executing the view object query by setting bind variable?
snippet as follows
viewObject.setNamedWherClauseParams("name","hei");
viewObject.executeQuery();
How to get the results from viewObject is my question..?
Thanks in advanceShould be something like
while (vo.hasNext()){
Row r = vo.next();
r.getAttribute....
You might want to read the "most commonly used methods" appendix in the ADF Developer Guide. -
How to run SQL files from Java?
Hi,
Can someone point me towards a link on how to run sql files in Java? Thanks.
P.S...if I've been completely blind please go easy on me!Sorry forgot the formating code thingy
public static boolean executeScript(File script, Connection conn){
boolean success = true;
success = script.exists();
if(success){
DEBUG.print("ES::READING SCRIPT:" + script.getAbsolutePath());
StringBuffer buffer = new StringBuffer();
success=readScript(script,buffer);
if(success){
try{
String creationScript = buffer.toString();
Statement st = conn.createStatement();
int start = 0;
int end = 0;
while (end != -1 && start < creationScript.length()) {
end = creationScript.indexOf("GO", start);
if (end != -1) {
DEBUG.print(creationScript.substring(start, end));
st.executeUpdate(creationScript.substring(start, end));
start = end + 2; //2 is the length of "GO"
st.close();
}catch(Exception e){
success=false;
DEBUG.printStackTrace(e);
}else{
DEBUG.print("ES::SCRIPT FILE DOES NOT EXISTS");
success=false;
return success;
public static boolean readScript(File script, StringBuffer buffer){
boolean success = true;
DEBUG.print("RS:: reading file :" + script.getAbsolutePath());
try{
InputStreamReader isr = new InputStreamReader(new FileInputStream(script),"UTF16");
int ch;
while ( (ch = isr.read()) > -1) {
buffer.append( (char) ch);
if (isr != null)
isr.close();
}catch(Exception e){
success=false;
DEBUG.printStackTrace(e);
return success;
} -
How to get Test Results to SQL w/o Coldfusion
Is there a way to get Captivate test results (or any results)
to SQL. I was thinking of using the SCORM interface?
A simple elegant solution would be great since I want to
build it into to all my componants.
Thanks in advance,
ScottIf your organization is running Sharpoint 3.x, you can use
the sharepoint learning kit which runs off of a sql back end. This
is a SCORM 2004 compliant LMS that can be found here:
http://www.codeplex.com/SLK
If you want to do this without an LMS, you can set up your
quiz to just send the score as in this article:
http://www.adobe.com/devnet/captivate/articles/store_cpresults_print.html
You steal the idea from here, but in your javascript, you can
do a pass your variables (quiz resutls), to an asp.net page that
places them into a SQL db. I'm working on such a solution right
now. That way, you don't need an LMS and you have complete control
over how and when the results are stored. -
How to get accurate results from sql code ?
Hello everybody,
I have a problem with some portion of my code.
I get more results than I specify in the where clause.
Here is the sample code:
c.gl_acct_id between '110'||'-'||'6890'||'-'||'69000'||'-'||'%'
and '110'||'-'||'7000'||'-'||'67999'||'-'||'%'
For some reason I also get the following results back:
110-6910-51001-001, and 110-6910-51003-001 But I don't need the 51001 and 51003. How do I specify in sql what range I really want. I was sure that the code above is correct. I guess not.
I would appreciate any help,
Thanks,
SonyaHave you tried using the query either of the following...
1) c.gl_acct_id between '110-6890-69000-000'
and '110-7000-67999-999'
and c.gl_acct_id not like '110-6910-51001-%'
and c.gl_acct_id not like '110-6910-51003-%'
assuming you have only 3 digits at the end of gl_acct.
2)If you know that your acct_id belongs to only 69000 or 67999
then
(c.gl_acct_id LIKE '110-6890-69000-%' OR
c.gl_acct_id LIKE '110-7000-67999-%' )
Plz. let me know if this not what you are looking for.
thanx
rajkiran
Here is the whole script:
select distinct c.gl_acct_id acct_no,
c.gl_acct_desc,
min(a.local_act_beg_bal) local_act_beg_bal,
sum(b.local_act_mtd_dr_amt) debits,
sum(b.local_act_mtd_cr_amt) credits,
nvl(min(a.local_act_beg_bal),0)+sum(nvl(b.local_act_mtd_dr_amt,0))-
sum(nvl(b.local_act_mtd_cr_amt,0)) end_bal
from gl_acct c, gl_acct_bal a, gl_acct_bal b
where c.org_unit_id = '110'
and b.gl_acct_id = c.gl_acct_id
and a.gl_acct_id = c.gl_acct_id
and c.sum_det_ind = 'D'
and c.gl_acct_class_ind in ( 'A' , 'L' , 'Q' , 'I' , 'E' )
and a.year_no = '2001'--:loyear
and a.period_no = '1'--:loperiod
and ( ( b.year_no = '2001'--:hiyear
and b.period_no between '1'--:loperiod
and'13')-- :hiperiod
and c.gl_acct_id between '110'||'-'||'6890'||'-'||'69000'||'-'||'%'
and '110'||'-'||'7000'||'-'||'67999'||'-'||'%'
group by c.gl_acct_id, c.gl_acct_desc
I want to have ability to specify ranges for gl_accoount.
Thanks,
Sonya -
How do I get SQL results to text, columns matching up, with data.
Hi All,
I have written a java application, that connect to a database, make a query, and return a resultset, that is then put into a LinkedList.
The main aim of the application is that it should take snapshots of the database at certain intervals, and store a textfile per tableName, with this data. Therefore, I want to create a range of .txt files, or even a html file. The application does not make use of any GUI functionality, so I am not using JFrames etc.
The main problem I have is how to get the column names and data mapped correctly, underneath it. Any ideas are welcome. Thank you.I hope you're not asking how you get the column names and data into the file in the same order. That is, obviously, by reading and writing them in the same order, of course. The columnnames from the ResultSetMetaData, and the columns from the ResultSet, of course.
I assume you're talking about how you get them to line up in pretty columns? Look at formatf in String or printf in PrintWriter. (And, probably, DatabaseMetaData to get the "sizes" of the varying columns.) -
CallableStatement, how to get function result ?
Hello all,
I know that this issue more relevant to JDBC, but it seems that their forum is more "sleepy" than that one therefor i trying my luck here with you...
I've a pl/sql function which get 2 int arguments, and return float result
I use CallableStatement in order to execute pl/sql function.
with CallableStatement.setInt i transfer argument to the function,
but i dont know how to "catch" function result (as i said earlier, function results is float)
any help here...
Thanks
Edited by: igalep132 on Nov 21, 2009 4:47 AMigalep132 wrote:
If you do have a PL/SQL function (specific syntax in PL/SQL) then you use the following form from the javadocs.
{?= call <procedure-name>[(<arg1>,<arg2>, ...)]}
[http://java.sun.com/javase/6/docs/api/java/sql/CallableStatement.html]
that's exactly what i did, but my teacher assistant told me that it's wrong, because CallableStatement uses for stored Procedures, but I have here a function (because it returns a value...) therefor i need to use PrepareStatment/Statement...Third person accounts are always hard to judge, but what you are claiming is wrong (whether the TA said it or not.)
First a prepared statement can in fact be used to run either a proc or function. So can statement for that matter.
However callable statement is provided as a convenience to run procs and functions.
There can however be reasons why a driver doesn't allow that - I have used a driver that didn't support callable statements at all (procs or functions.)
That said the the format I gave you is specifically modeled for functions. -
How to get the parameter from Java Script into the Parameter crystal Report
Hi All,
Crystal Report is integrated with Oracle 10g. I created the base SQL query for col1, col2, col3 and col4. Java Script pass parameter value (185) to Col1.
My question is how to create crystal report to make Col1 as parameter and how to get the parameter value 185(Col1) from Java Script. Is there any additional code I need to include in the crystal report?
FYI.
Java script sends the right parameter value.There is no issue in java script.
This is an automatic scheduled process when batch runs, Java script should pass the parameter value and the crystal report should get the value and produce the output report.Not sure if this is an application question or if you are trying to hook into Crystal Reports parameter UI? If the later then no option other than report design. If an application then I can move this to the Java Forums.
If you are asking how to alter the parameters I suggest you remove the Java reference and post a new question so it's not confusing the issue.
Please clarify? -
How to display sqlplus result in java?
I want to call sqlplus to execute some sql commands in java,but how can i print the result of sqlplus?
In java code ,i call sqlplus like:
Process p;
//execute the command
p = Runtime.getRuntime().exec(commandString);
//print return result of the command
InputStream inputStream = p.getInputStream();
How to display the execution result?
Edited by: Yi on Feb 26, 2012 11:41 PMYou can use ProcessBuilder. This code launches sql*plus and runs the script in the 'filename' variable. It displays the results in NetBeans console.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.File;
import java.util.Map;
public class test1 {
public static void main (String args []) {
test_script();
public static void test_script () {
String fileName = "@test_table.sql";
String sqlPath = "E:\\";
String sqlCmd = "sqlplus";
String arg1 = "user/password@sid"; -- plug in your user, password and db name
String arg2 = fileName;
try {
String line;
ProcessBuilder pb = new ProcessBuilder(sqlCmd, arg1, arg2);
Map<String, String> env = pb.environment();
env.put("VAR1", arg1);
env.put("VAR2", arg2);
pb.directory(new File(sqlPath));
pb.redirectErrorStream(true);
Process p = pb.start();
BufferedReader bri = new BufferedReader
(new InputStreamReader(p.getInputStream()));
BufferedReader bre = new BufferedReader
(new InputStreamReader(p.getErrorStream()));
while ((line = bri.readLine()) != null) {
System.out.println(line);
bri.close();
while ((line = bre.readLine()) != null) {
System.out.println(line);
bre.close();
System.out.println("Done.");
catch (Exception err) {
err.printStackTrace();
}Here is the contents of the script placed at E:\\test_table.sql
Prompt drop TABLE ANOTHER_TEST;
DROP TABLE ANOTHER_TEST CASCADE CONSTRAINTS
Prompt Table ANOTHER_TEST;
CREATE TABLE ANOTHER_TEST
BATCH_SEQ NUMBER,
BATCH_GROUP_ID NUMBER,
STATUS_FLAG VARCHAR2(30 BYTE),
OBJ_BEING_PROCESSED VARCHAR2(80 BYTE),
BATCH_RUN_START_DTTM DATE,
BATCH_RUN_END_DTTM DATE,
CREATE_DTTM DATE,
CREATE_USER VARCHAR2(30 BYTE),
UPDATE_DTTM DATE,
UPDATE_USER VARCHAR2(30 BYTE)
LOGGING
NOCOMPRESS
NOCACHE
PARALLEL ( DEGREE DEFAULT INSTANCES DEFAULT )
MONITORING
COMMENT ON TABLE ANOTHER_TEST IS 'This is a test table.'
EXIT
/ -
How to get applets running with Java Plug-in on Win but also on Mac OS X???
I've converted to the use of Java Plug-in for my applets, but I need to have those same applets executable from browsers on Mac OS X platform. Surely this has been done, but I don't see how. The browsers I've tried on Mac OS X (Netscape, IE) don't seem to recognize the <OBJECT> tag used for the java plug-in. I've seen no news about the Java plug-in being ported to Macs. How can one get the same applet to run with the Java plug-in on Windows browsers, and also to run with at least one of the common browsers on Mac OS X? Any help would be SO much appreciated!
Those ten dukes look good to me. But the passing of fifteen months has me thinking you've probably moved on. In any case, here's my effort.
I've been through a trial trying to get my applet, developed with 1.4.1_03, to run on my Mac OS X v.10.2.6 in multiple browsers. I'm posting my results here. Comments and feedback are welcome.
JVM support for 1.4.1 is limited to the Safari browser. All other browsers running in Mac OS X that I've tried ( Camino, Opera, Internet Explorer, Mozilla ) are using the 1.3.1 plugin. According to a bug report by Mozilla on this topic ( see Bugzilla Bug # 197813 http://bugzilla.mozilla.org/show_bug.cgi?id=197813 )
with the release of Apple's version of Sun's Java 1.4.1 the applet programming model has changed, and only Safari has adapted with this change. Other browsers, according to the report, could not because of a lack of documentation. The use of the MRJCarbon plugin offered by Mozilla (here - http://www.mozilla.org/oji/MRJPluginCarbon.html) only allows Mozilla to use the J 1.3.1. And I have not found any information on the Microsoft site about how to get IE 5.2 to recognize the newer version of Java.
Regarding the use of the OBJECT tag in Safari, it is a matter of debate. A current post on this topic exists in the Applet Development forum:
http://forum.java.sun.com/thread.jsp?forum=421&thread=441002
In my experience, I have not been able to determine that Safari v1.0 recognizes the OBJECT tag. My experience is that the APPLET tag is required to run applets in Safari. The Bugzilla report echoes the problem with the BadMagicNumber error that can arise in Safari. Nonetheless, I enjoy Safari and I enjoy Mac OS X.
Maybe you are looking for
-
Has anyone tried to download Rosetta Stone to their iPad? Can it be done?
I'm going to be on an overseas flight and thought I'd learn Spanish during the 13 hours.
-
HT5234 Macbook Air Power Adapter
Ok, I have just bought a brand, spanking new Macbook Air 13" and sold my 15" Late 2008 Unibody Macbook Pro to a friend. The thing is, I now have a spare MacBook Pro charger (kept the original at home and had a spare at the office). Can this spare Mac
-
I purchased a song on iTunes and it shows up in the song list with an exclamation point on the side of it. It says the song could not be found. I have done a search and can't find it but iTunes won't let me download or buy it again. Help!!
-
Back up 2 different iphone5's on the same computer or same itunes/icloud account?
How do I back up two different iphone5's on the same computer or same itunes/icloud account? I'm afraid one phone will end up with the other person's cell phone ap's and information on it...since this happened once before. How do I save them separate
-
Sluggish performance - Mac Mini and MBP?
I'm experiencing sluggish performance on my Mac Mini with Leopard (upgrade installation) when using the genie effect, expose, spaces, gadgets, 3d dock, etc. It's jerky, as if the animation is missing frames. Is it related to the graphics card? I also