Need to simplify the insert stmt
Hi,
I have a below three update statements inside the procedure.and using same kind of FROM and WHERE clause condition .can some one help to simplify 3 update statements as one statement or least to simplify to first update condition.
UPDATE REP_ITEM_STAT_OPN SET
TOT_STUD_CORR_ANS_BY_ITEM = NVL((SELECT COUNT(1)
FROM PSYCHOMETRIC_ITEM_STAT_OPN
WHERE RESPONSE_IS_CORRECT = 1
AND REP_ITEM_STAT_OPN.ITEM_ID=TV_REP_ITEM_STAT_OPN(LN_SS_OPN)
AND REP_ITEM_STAT_OPN.ITEM_ID = PSYCHOMETRIC_ITEM_STAT_OPN.ITEM_ID
GROUP BY ITEM_ID ),0) ,
POOL_CREATED_DT = (SELECT MAX(A.POOL_CREATED_DT)
FROM PSYCHOMETRIC_ITEM_STAT_OPN A
WHERE REP_ITEM_STAT_OPN.ITEM_ID=TV_REP_ITEM_STAT_OPN(LN_SS_OPN)
AND REP_ITEM_STAT_OPN.ITEM_ID = A.ITEM_ID
GROUP BY ITEM_ID),
TOT_SS_BY_ITEM = NVL((SELECT SUM(SCALE_SCORE)
FROM PSYCHOMETRIC_ITEM_STAT_OPN
WHERE REP_ITEM_STAT_OPN.ITEM_ID=TV_REP_ITEM_STAT_OPN(LN_SS_OPN)
AND REP_ITEM_STAT_OPN.ITEM_ID = PSYCHOMETRIC_ITEM_STAT_OPN.ITEM_ID
GROUP BY ITEM_ID ),0),
AVG_SS_CORR_BY_ITEM = NVL((SELECT AVG(SCALE_SCORE)
FROM PSYCHOMETRIC_ITEM_STAT_OPN
WHERE RESPONSE_IS_CORRECT = 1
AND REP_ITEM_STAT_OPN.ITEM_ID=TV_REP_ITEM_STAT_OPN(LN_SS_OPN)
AND REP_ITEM_STAT_OPN.ITEM_ID = PSYCHOMETRIC_ITEM_STAT_OPN.ITEM_ID
GROUP BY ITEM_ID ),0) ,
AVG_SS_INCORR_BY_ITEM = NVL((SELECT AVG(SCALE_SCORE)
FROM PSYCHOMETRIC_ITEM_STAT_OPN
WHERE RESPONSE_IS_CORRECT <> 1
AND REP_ITEM_STAT_OPN.ITEM_ID=TV_REP_ITEM_STAT_OPN(LN_SS_OPN)
AND REP_ITEM_STAT_OPN.ITEM_ID = PSYCHOMETRIC_ITEM_STAT_OPN.ITEM_ID
GROUP BY ITEM_ID ),0),
STD_DEV_SS = NVL((SELECT STDDEV(SCALE_SCORE)
FROM PSYCHOMETRIC_ITEM_STAT_OPN
WHERE REP_ITEM_STAT_OPN.ITEM_ID=TV_REP_ITEM_STAT_OPN(LN_SS_OPN)
AND REP_ITEM_STAT_OPN.ITEM_ID = PSYCHOMETRIC_ITEM_STAT_OPN.ITEM_ID
GROUP BY PSYCHOMETRIC_ITEM_STAT_OPN.ITEM_ID),0),
OVERALL_IER = (CASE
WHEN LN_TOT_RECORDS = 0 THEN '.'
ELSE TO_CHAR(TOT_STUD_BY_ITEM/LN_TOT_RECORDS)
END),
MEAN_TIME = NVL((SELECT TO_CHAR(AVG(RESPONSE_DURATION))
FROM PSYCHOMETRIC_ITEM_STAT_OPN
WHERE REP_ITEM_STAT_OPN.ITEM_ID=TV_REP_ITEM_STAT_OPN(LN_SS_OPN)
AND REP_ITEM_STAT_OPN.ITEM_ID = PSYCHOMETRIC_ITEM_STAT_OPN.ITEM_ID
GROUP BY PSYCHOMETRIC_ITEM_STAT_OPN.ITEM_ID),'.'),
STD_DEV_TIME = CASE WHEN TOT_STUD_BY_ITEM =0 OR TOT_STUD_BY_ITEM=1 THEN '.'
ELSE NVL(( SELECT TO_CHAR(STDDEV(RESPONSE_DURATION)) FROM PSYCHOMETRIC_ITEM_STAT_OPN
WHERE REP_ITEM_STAT_OPN.ITEM_ID=TV_REP_ITEM_STAT_OPN(LN_SS_OPN)
AND REP_ITEM_STAT_OPN.ITEM_ID = PSYCHOMETRIC_ITEM_STAT_OPN.ITEM_ID
GROUP BY PSYCHOMETRIC_ITEM_STAT_OPN.ITEM_ID),'0')END,
CUM_IER = (CASE
WHEN LN_TOT_FOURYR_RECORDS = 0 THEN '.'
ELSE TO_CHAR((SELECT TOT_STUD_FOUYR_BY_ITEM FROM REP_ITEM_STAT_OPN
WHERE ITEM_ID=TV_REP_ITEM_STAT_OPN(LN_SS_OPN))/LN_TOT_FOURYR_RECORDS)
END )
WHERE REP_ID = LN_SEQ_REP_ID
AND REP_ITEM_STAT_OPN.ITEM_ID=TV_REP_ITEM_STAT_OPN(LN_SS_OPN);
COMMIT;
UPDATE REP_ITEM_STAT_OPN SET
OVERALL_ITEM_DIFF = (CASE
WHEN TOT_STUD_BY_ITEM = 0 THEN '.'
ELSE TO_CHAR(TOT_STUD_CORR_ANS_BY_ITEM/TOT_STUD_BY_ITEM)
END)
WHERE REP_ID = LN_SEQ_REP_ID
AND REP_ITEM_STAT_OPN.ITEM_ID=TV_REP_ITEM_STAT_OPN(LN_SS_OPN);
COMMIT;
UPDATE REP_ITEM_STAT_OPN SET
ITEM_DISCRIMINATION = (CASE
WHEN TOT_STUD_BY_ITEM =0 OR TOT_STUD_BY_ITEM=1 THEN '.'
WHEN STD_DEV_SS = 0 THEN '.'
WHEN OVERALL_ITEM_DIFF=0 OR OVERALL_ITEM_DIFF=1 THEN '.'
ELSE TO_CHAR((((AVG_SS_CORR_BY_ITEM-AVG_SS_INCORR_BY_ITEM) * SQRT(OVERALL_ITEM_DIFF*(1-OVERALL_ITEM_DIFF)))/STD_DEV_SS)*SQRT(TOT_STUD_BY_ITEM/(TOT_STUD_BY_ITEM-1)))
END)
WHERE REP_ID = LN_SEQ_REP_ID
AND REP_ITEM_STAT_OPN.ITEM_ID=TV_REP_ITEM_STAT_OPN(LN_SS_OPN);
COMMIT;
You can simplify the first update as follows
NOT TESTED
UPDATE REP_ITEM_STAT_OPN SET
(TOT_STUD_CORR_ANS_BY_ITEM, POOL_CREATED_DT , TOT_SS_BY_ITEM, AVG_SS_CORR_BY_ITEM, AVG_SS_INCORR_BY_ITEM, STD_DEV_SS, MEAN_TIME, STD_DEV_TIME) =
(SELECT COUNT(1), nvl(MAX(A.POOL_CREATED_DT),0), nvl(SUM(SCALE_SCORE),0), nvl(AVG(SCALE_SCORE),0),
nvl(AVG(SCALE_SCORE),0),nvl(STDDEV(SCALE_SCORE),0), nvl(TO_CHAR(AVG(RESPONSE_DURATION)),'.'),
CASE WHEN TOT_STUD_BY_ITEM =0 OR TOT_STUD_BY_ITEM=1 THEN '.' ELSE NVL(TO_CHAR(STDDEV(RESPONSE_DURATION)),'.')
FROM PSYCHOMETRIC_ITEM_STAT_OPN
WHERE REP_ITEM_STAT_OPN.ITEM_ID=TV_REP_ITEM_STAT_OPN(LN_SS_OPN)
AND REP_ITEM_STAT_OPN.ITEM_ID = PSYCHOMETRIC_ITEM_STAT_OPN.ITEM_ID),
OVERALL_IER = (CASE WHEN LN_TOT_RECORDS = 0
THEN '.' ELSE TO_CHAR(TOT_STUD_BY_ITEM/LN_TOT_RECORDS)
END),
***_IER = (CASE
WHEN LN_TOT_FOURYR_RECORDS = 0 THEN '.'
ELSE TO_CHAR((SELECT TOT_STUD_FOUYR_BY_ITEM FROM REP_ITEM_STAT_OPN
WHERE ITEM_ID=TV_REP_ITEM_STAT_OPN(LN_SS_OPN))/LN_TOT_FOURYR_RECORDS)
END )
WHERE REP_ID = LN_SEQ_REP_ID
AND REP_ITEM_STAT_OPN.ITEM_ID=TV_REP_ITEM_STAT_OPN(LN_SS_OPN);
COMMIT;Max
[My Italian Oracle blog|http://oracleitalia.wordpress.com/2009/12/04/espressioni-regolari-in-oracle-sql-e-plsql/]
Edited by: Massimo Ruocchio on Dec 15, 2009 11:20 AM
SOME CORRECTIONS
Similar Messages
-
Need to disable the insert edit in Timeline.
I'm piecing together a video to music right now and am finding that, when I drop and drag clips from the viewer to the timeline, I accidentally use the insert edit, only to find later on that some of my clips have been unknowingly moved around. Is there any way to disable the insert edit arrow in the timeline and only have the overwrite edit arrow active?
Thanks!If you prefer dragging directly to the timeline, then you'll need to pay attention to where your mouse pointer is located in the appropriate video track before you release the mouse button. If you look at an empty video track, you'll notice a line that runs just above the center of the track. If you drag a clip and your mouse is above that divider line, you'll perform an Insert Edit, if your mouse is below that divider, then you'll perform an Overwrite Edit. You'll see the mouse pointer change indicating the edit that you're about to perform.
From the FCP Users Manual:
http://dl.getdropbox.com/u/19589/Timeline%20Edit%20Zones.png
I will second the advice that was already given, performing edits with the keyboard or the Canvas overlays is MUCH more accurate than dragging directly to the timeline. -
Hi,
How to check whether the following trigger is working properly or not?
CREATE OR REPLACE TRIGGER employee_ins_t1
BEFORE INSERT
ON employee
FOR EACH ROW
BEGIN
SELECT employee_seq.nextval
INTO :new.id
FROM dual;
END;please excuse me if this is very newbie questionYeah , I tried to insert some data into the table but getting the following error: So confused how to check the trigger is working
SQL> insert into employee(id, ename) values (null, 'abc');
insert into employee(id, ename) values (null, 'abc')
ERROR at line 1:
ORA-08004: sequence EMPLOYEE_SEQ.NEXTVAL exceeds MAXVALUE and cannot be
instantiatedEdited by: Smile on Feb 19, 2013 2:24 AM -
How can i insert the insertion point in each paragraph first
Hi all
Please find the below script, this script place the insertion point in end of the each paragraph, but i need to place the insertion point in first letter of the each paragraph. Please help.
var myDoc=app.documents.item(0)
var myLib=app.libraries.item(0)
app.findTextPreferences=null;
app.changeTextPreferences=null;
app.findChangeTextOptions.caseSensitive=false;
app.findChangeTextOptions.includeFootnotes=false;
app.findTextPreferences.appliedParagraphStyle="TX"
app.findTextPreferences.findWhat="^p"
var myFinds=myDoc.findText()
for(i=0; i<myFinds.length; i++)
var myIcon=myLib.assets.item("Para").placeAsset(myFinds[i].insertionPoints[0])[0]
myIcon.appliedObjectStyle=myDoc.objectStyles.item("Para No")
Thanks & Regards
Nithin@Nithin – inserting the anchor by placing the asset is changing the position of the next anchor, because the script's for-loop is running from the first found instance to the last found one.
If you go through all the found instances from back to forth would be one solution.
var myDoc=app.documents.item(0)
var myLib=app.libraries.item(0)
app.findGrepPreferences=null;
app.changeGrepPreferences=null;
app.findChangeGrepOptions.includeFootnotes=false;
app.findGrepPreferences.appliedParagraphStyle="TX"
app.findGrepPreferences.findWhat=".+\\r"
var myFinds=myDoc.findGrep()
for(i=myFinds.length-1; i>=0; i--)
var myIcon=myLib.assets.item("Para").placeAsset(myFinds[i].insertionPoints[0])[0]
myIcon.appliedObjectStyle=myDoc.objectStyles.item("Para No")
Another one would be doing the search from back to forth and not changing the for-loop:
var myFinds=myDoc.findGrep(true);
Array of Text findGrep ([reverseOrder: bool])
Finds text that matches the find what value.
Uwe -
URGENT !! Capture the insert and select on database
Hi,
I need to capture the inserts and selects on the database.
What are the options available on 9i?
Thanks in advance!I don;t know how many times I've had to say this, but since I've had to say it to my boss, it bears repeating here:
The SPFILE makes absolutely zero, null, nought difference to whether or not something is changeable dynamically or not. Not one bit, one whit or one iota.
Parameters are as static or as dynamic as they were when init.oras rules the roost. Check in V$PARAMETER: if the thing says ISSYSMODIFIABLE is TRUE, then the parameter can be altered with an alter system command -and that's true whether you're using an init.ora or an spfile. If it says ISSYSMODIFIABLE=FALSE, then the parameter CANNOT be altered with an alter system command, and that's true whether you're using an init.ora or an spfile.
Now comes the subtlety: if you add SCOPE=SPFILE to your alter system command then you aren't actually altering the system at all. All you're doing is asking the instance to edit the spfile. So an alter system set db_block_size=67238 scope=spfile will work, because you're not actually asking to alter the current block size at all. You're merely asking the instance to do what you would otherwise have done with notepad or gedit to a traditional init.ora.
Only if you SCOPE=MEMORY is your alter system command actually trying to change the currently running instance.
Of course, the trouble starts when you miss off a SCOPE clause, because then you get SCOPE=BOTH, which means MEMORY+SPFILE. But try that on a parameter which is SYSMODIFIABLE=FALSE: it won't work, because the MEMORY bit trips over the fact that the parameter is not system (dynamically) modifiable. Which just goes to prove that the existence of an SPFILE changes ABSOLUTELY NOTHING about whether a parameter can be dynamically modified or not.
So no, the sentence "my database is using spfile and I have option to use alter system command" makes zero sense if, by it, you mean "I'm using an spfile so can I change things dynamically which I wouldn't be allowed to if I was stuck using a boring old init.ora"
The answer is always and forever, "NO"!
I blame a certain bouffant-haired so-called expert for first promulgating this myth that all parameters suddenly became dynamic in the presence of an spfile. It was never true when he wrote it. It isn't true now. It never will be true. It just happens to be the case that "alter system..scope=spfile" is Oracle's equivalent of "vi init.ora" as far as spfiles are concerned. -
How can I change the insert SWF File, I need to add a few things and make it better?
How can I change the insert SWF File, I need to add a few things and make it better? Is there an option inside of the dreamweaver menu that I am not looking at. It would make it easier on me if I changed some things around and didn't have to do it all myself each time I used it. Just incase you was needing to remember what swf flash was, It is not a swf video either.
<object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="640" height="480">
<param name="movie" value="Sonic Kaboom.swf">
<param name="quality" value="high">
<param name="wmode" value="opaque">
<param name="swfversion" value="9.0.115.0">
<!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
<param name="expressinstall" value="../Scripts/expressInstall.swf">
<!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="Sonic Kaboom.swf" width="640" height="480">
<!--<![endif]-->
<param name="quality" value="high">
<param name="wmode" value="opaque">
<param name="swfversion" value="9.0.115.0">
<param name="expressinstall" value="../Scripts/expressInstall.swf">
<!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
<div>
<h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p>
</div>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
</div>If I understand correctly, Sonic Kaboom.swf needs to be edited in a separate Flash authoring program and then reinserted into your HTML document.
As Murray said, Flash is dead. Nobody uses it anymore. We use HTML5, CSS3 and JavaScript animations which have universal support from Smartphones, Tablets and other web devices that can't support Flash. Look at Edge Animate.
HTML animation | Download free Adobe Edge Animate CC trial
Nancy O. -
I accidentally added the app store apple id wrong, then I was able to put the right one but now that I need to update the application tells me to insert the id of the psw wrong, how do I change it?
You must update the apps with the Apple ID that they are purchased with.
The only way to get round this is to re-purchase the app with the new Apple ID. -
Need help identifying the application responsible for an insert...
Hi,
I'm a MSSQL guy and Oracle is still a bit mysterious to me. I'm looking for some assistance tracking down the application in an environment which is responsible for particular inserts.
For example, suppose I have 10 different programs running and inserting values to a DB. I need to know which one of them inserts a "0" in a particular column.
I found a trigger which will tell me the user, unfortunately these programs use a shared credential so that doesn't help me.... here's what I've got:
CREATE OR REPLACE TRIGGER check_for_zero_insert
AFTER INSERT
ON DATA_TABLE_0001
FOR EACH ROW
DECLARE
v_username varchar2(10);
BEGIN
-- Find username of person performing the INSERT into the table
SELECT user INTO v_username
FROM dual;
-- Insert record into audit table
INSERT INTO audit_table
( samplevalue
sampletime,
username )
VALUES
( :sampletime,
:samplevalue
v_username );
END;
But again, username won't help me, I need the originating process if at all possible (either an executable name, PID, or something to identify the specific application on the other side.)use this in your trigger
select sys_context('USERENV','OS_USER') ||'-' ||user into v_username from dual;
You might need to increase the v_username data type length.
Thanks,
GPU -
I have the following code:
<%
If (CStr(Request("MM_insert")) = "form1") Then
If (Not MM_abortEdit) Then
' execute the insert
Dim MM_editCmd
Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_NewFLSSARDB_STRING
MM_editCmd.CommandText = "INSERT INTO DocumentTable (Title, DocLink, UpdatedBy, UpdateDate, Type, Comments) VALUES (?, ?, ?, ?, ?, ?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 255, Request.Form("DocumentName")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 202, 1, 255, Request.Form("DocLocation")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 202, 1, 255, Request.Form("UpdatedBy")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 135, 1, -1, MM_IIF(Request.Form("UpdatedDate"), Request.Form("UpdatedDate"), null)) ' adDBTimeStamp
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 202, 1, 255, Request.Form("Type")) ' adVarWChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 203, 1, 1073741823, Request.Form("Comments")) ' adLongVarWChar
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
' append the query string to the redirect URL
Dim MM_editRedirectUrl
MM_editRedirectUrl = "testFLSSARSuperAdminIndex.asp"
If (Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
Response.Redirect(MM_editRedirectUrl)
End If
End If
%>
For param2 above I need to add the directory "Docs/" to the command so that the file can be found by the User. How do I do that?If all documents are going to the "/Docs" folder, then I wouldn't include it in the inserted data as you can just add it dynamically where needed. If you do want to include it and it's not part of the posted form data, then just concatenate it (&) prior to inserting into the table.
-
i need to change the sim card, when i insert the new card it showing "no sim" how can i solve this problm?
Get a working SIM from your carrier?
Was your phone jailbroken or hacked to unlock it? -
I am working on a publishing site collection using the enterprise wiki template. Add when I want to add a new Picture from my Pc to the wiki page, I will be prompted with the following dialog:-
So can anyone advice how i can bypass this dialog and directly add the imag to the wiki page?
i tried modifying the "Images" content type by hiding the above fields, but still i will be prompted to enter the following :-Hi,
According to your post, my understanding is that you want to directly insert pictures inside a wiki page without the need to enter the picture's properties.
Per my knowledge, you can use javascript to bypass Edit Properties Page while uploading pictures.
Here are some similar articles for your reference:
How to bypass Edit Properties
Page while uploading documents in a document library
How to bypass Edit Properties Page while uploading documents in a
SharePoint and .NET: How to bypass Edit Properties Page or Skip EditForm.aspx Page while uploading documents in a document library
Best Regards,
Linda Li
Linda Li
TechNet Community Support -
As described above.
I have spent far too much time investigating this issue! All I would like to do is have the insertion point cursor (the 'I' shaped text thing) not dissapear when navigating text in a word document with the arrow keys.
Some forums say it's an apllication issue, i.e. microsoft, others say you used to be able to do it in older versions of mac os'.
This isn't a problem for Mac programmes. Obviously it is an issue when Microsoft programmes cross over to Mac. If the computer was a PC then I could customise the blinking rate, turn it on or off etc under the control panel options. With a Mac running MS Office I have not got this option.
So how do I go about telling Apple of my displeasure? So hopefully for future editions of OS or Office for Mac this very minor but completely infuriating problem gets ironed out?
Cheers xThank you Ralph n Kurt, very quick off the mark boys, well done
Just checking in to inform you that today, after putting up with the issue for over a year, it has sorted itself out, MIRACLE! I don't know how but I've got a fully trackable insertion point when I navigate with my arrow keys!!
Do you think it's the big-wigs (because I complained to both Mac n MS) tweaking my computer behind the secenes? and if so which one would've done it? My money's on the geniusii.
Either way I am well chuffed and thanks again!
x -
Cannot find "Structure" menu under the Insert tab. Need it to insert a header
I just downloaded a trial version of DW CS6 and am following the on-line tutorial, but cannot find the "Structure" option under the "Insert" tab when creating an HTML document. Where di it go?
I think the confusion here is you appear to be following along some resource for DWCC while using DWCS6.
There are many changes between DWCS6 and DWCC. Actually, there are quite a few changes between DWCS6 Disk version and DWCS6 Cloud version with even more between both of those and DWCC (and now DWCC 2014).
With the speed that Adobe applications are changing with the Creative Cloud delivery system, you really must make sure you are using the correct resource version for your program version. -
Using the Insert statement in a Java program without hardcoding the data
hello.
this is james mcfadden. i have developed a program called Demo.java, which is used with another program called QueryTableModel.java (a program that allows data to be viewed in a JTable). The Demo.java program displays a menu, connects to a database, allows the user to add data into the database and allows the user to view data that is already in the database. I have a problem with the Demo.java program. I have hardcoded the Insert statement in it. How do you use the Insert statement to put data into a database without hardcoding the data?
import java.awt.*;//Contains all of the classes for creating user interfaces and for painting graphics and images
import java.awt.event.*;//Provides interfaces and classes for dealing with different types of events fired by AWT components
import javax.swing.*;//Provides a set of lightweight components that, to the maximum degree possible, work the same on all platforms
import javax.swing.table.*;//Provides classes and interfaces for dealing with javax.swing.JTable
import javax.swing.JOptionPane;//provides a class that makes it easy to pop up a standard dialog box that prompts users for a value or informs them of something
import java.sql.*;//Provides the API for accessing and processing data stored in a data source using the Java programming language
public class Demo extends JFrame{
static String url = "jdbc:odbc:VideoLibrary";//a static variable that allows a connection to be made to a database called VideoLibrary
static Statement stmt;//a static variable that allows a statement to be made once a connection is set up
static Connection con;//a static interface that allows a connection to be made to a database
//global variables
JTextField hostField;//a class that allows a line of text to be changed
JTextField queryField;//a class that allows a line of text to be changed
QueryTableModel qtm;//a class that shows and changes regular two-dimensional tables of cells
JComboBox comboBox;//a class that puts a button or editable field and a drop-down list together
public static void main(String args[]){
int choice=-1;//a variable of type int that is set to -1
do{
choice=getChoice();//invokes the method getChoice()
if(choice!=0){
getSelected(choice);//invokes the method getSelected(choice)
}//end if
//if the user chooses 5, it will cause him or her to exit the system
}while(choice!=5);//end do-while
System.exit(0);//closes down the menu screen
}//end main
public static int getChoice(){
String choice;//a variable of type string
int ch;//a variable of type int
choice = JOptionPane.showInputDialog(null,"1. Maintain product details\n"+"2. Maintain member details\n"+"3. Maintain rental details\n"+"4. View product, member and rental details\n"+"5. Log Off\n\n"+"Enter your choice");//asks the user for some input
ch = Integer.parseInt(choice);//a class that wraps a value of the primitive type int in an object
return ch;//a method that returns an integer value
}//end getChoice
public static void getSelected(int choice){
if(choice==1){
maintainProductDetails();//invokes the method maintainProductDetails()
}//end if
if(choice==2){
maintainMemberDetails();//invokes the method maintainMemberDetails()
}//end if
if(choice==3){
maintainRentalDetails();//invokes the method maintainRentalDetails()
}//end if
if(choice==4){
Demo test = new Demo();//invokes the constructor Demo()
test.setVisible(true);//shows the JTable component by marking it as visible
}//end if
}//end getSelected
public static Connection getConnection(){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//used to create a JDBC connection using a database
}//end try
catch(java.lang.ClassNotFoundException e){//causes an exception to be thrown when an application tries to load in a class through its string name
System.err.print("ClassNotFoundException: ");//displays an error message
System.err.println(e.getMessage());//returns the exception that was raised if an error occurred while attempting to load the ClassNotFoundException class
}//end catch
try {
con=DriverManager.getConnection(url,"","");//tries to create a connection with the database using the DriverManager class
}//end try
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());//returns an SQL error message
}//end catch
return con;
}//end getConnection
public static void maintainProductDetails(){
Connection con = getConnection();//creates a connection with the database
String addProduct1, addProduct2, addProduct3, addProduct4, addProduct5, addProduct6, addProduct7, addProduct8, addProduct9, addProduct10;//string variables that represent information about the different types of product data that will be stored in the database
addProduct1 = "insert into Product values (110001, 'The Killers - Sams Town', 5.00, 'G', 'CD', 2006)";
addProduct2 = "insert into Product values (110002, 'Robbie Williams - Rudebox', 5.00, 'G', 'CD', 2006)";
addProduct3 = "insert into Product values (110003, 'Razorlight - Razorlight', 5.00, 'G', 'CD', 2006)";
addProduct4 = "insert into Product values (110004, 'My Chemical Romance - The Black Parade', 5.00, 'G', 'CD', 2006)";
addProduct5 = "insert into Product values (110005, 'Snow Patrol - Eyes Open', 5.00, 'G', 'CD', 2006)";
addProduct6 = "insert into Product values (110006, 'Scissor Sisters - Ta-Dah!', 5.00, 'G', 'CD', 2006)";
addProduct7 = "insert into Product values (110007, 'Lovesounds - Justin Timberlake', 5.00, 'G', 'CD', 2006)";
addProduct8 = "insert into Product values (110008, 'Director - We thrive on big cities', 5.00, 'G', 'CD', 2006)";
addProduct9 = "insert into Product values (110009, 'Roxette - Roxette hits', 5.00, 'G', 'CD', 2006)";
addProduct10 = "insert into Product values (110010, 'Pussy Cat Dolls - PCD', 5.00, 'G', 'CD', 2006)";
try {
stmt = con.createStatement();//Creates a Statement object for sending SQL statements to the database
//statements are allowed to be made once a connection is set up
stmt.executeUpdate(addProduct1);
stmt.executeUpdate(addProduct2);
stmt.executeUpdate(addProduct3);
stmt.executeUpdate(addProduct4);
stmt.executeUpdate(addProduct5);
stmt.executeUpdate(addProduct6);
stmt.executeUpdate(addProduct7);
stmt.executeUpdate(addProduct8);
stmt.executeUpdate(addProduct9);
stmt.executeUpdate(addProduct10);
stmt.close();//closes the Statement object
con.close();//terminates the connection with the database
}//end try
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());//returns an SQL error message
}//end catch
}//end maintainProductDetails
public static void maintainMemberDetails(){
Connection con = getConnection();//creates a connection with the database
String addMember1, addMember2, addMember3, addMember4, addMember5, addMember6, addMember7, addMember8, addMember9, addMember10;//string variables that represent information about the member data that will be stored in the database
addMember1 = "insert into Member values (1234, 'Ann', 'Smyth', 'Upper Killult, Falcarragh, Co. Donegal', '(074)-9135210', '(087)-2030172', #5/11/85#, #5/12/06#)";
addMember2 = "insert into Member values (2345, 'John', 'Murphy', 'Lower Killult, Falcarragh, Co. Donegal', '(074)-9135211', '(087)-2030173', #4/12/85#, #6/13/06#)";
addMember3 = "insert into Member values (1324, 'James', 'McFadden', 'Lower Ardsbeg, Gortahork, Co. Donegal', '(074)-9165314', '(087)-2030171', #4/11/85#, #6/14/06#)";
addMember4 = "insert into Member values (1235, 'Frankie', 'Ferry', 'Ardsmore, Gortahork, Co. Donegal', '(074)-9165325', '(087)-2031234', #6/13/60#, #6/15/06#)";
addMember5 = "insert into Member values (1236, 'Daniel', 'McKimm', 'Ballyness, Falcarragh, Co. Donegal', '(074)-9135212', '(087)-2030184', #5/14/73#, #6/16/06#)";
addMember6 = "insert into Member values (2346, 'Stephen', 'Doohan', 'Ballyness, Falcarragh, Co. Donegal', '(074)-9135213', '(087)-2030185', #6/13/85#, #5/13/06#)";
addMember7 = "insert into Member values (2347, 'James', 'Ferry', 'Meenlaragh, Gortahork, Co.Donegal', '(074)-9165360', '(087)-2031345', #9/12/85#, #5/14/06#)";
addMember8 = "insert into Member values (2348, 'Liam', 'Cannon', 'Derryconner, Gortahork, Co.Donegal', '(074)-9165324', '(087)-2031456', #4/11/86#, #5/15/06#)";
addMember9 = "insert into Member values (2401, 'Ciaran', 'Ferry', 'Brinalack, Gweedore, Co.Donegal', '(074)-9176425', '(087)-2030282', #9/12/85#, #5/16/06#)";
addMember10 = "insert into Member values (2402, 'Ciaran', 'McGee', 'Derrybeg, Gweedore, Co.Donegal', '(074)-9176536', '(087)-2030393', #9/14/85#, #5/18/06#)";
try{
stmt = con.createStatement();//Creates a Statement object for sending SQL statements to the database
//statements are allowed to be made once a connection is set up
stmt.executeUpdate(addMember1);
stmt.executeUpdate(addMember2);
stmt.executeUpdate(addMember3);
stmt.executeUpdate(addMember4);
stmt.executeUpdate(addMember5);
stmt.executeUpdate(addMember6);
stmt.executeUpdate(addMember7);
stmt.executeUpdate(addMember8);
stmt.executeUpdate(addMember9);
stmt.executeUpdate(addMember10);
stmt.close();//closes the Statement object
con.close();//terminates the connection with the database
}//end try
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());//returns an SQL error message
}//end catch
}//end maintainMemberDetails
public static void maintainRentalDetails(){
Connection con = getConnection();//creates a connection with the database
String addRental1, addRental2, addRental3, addRental4, addRental5, addRental6, addRental7, addRental8, addRental9, addRental10;//string variables that represent information about the loan data that will be stored in the database
addRental1 = "insert into Rental values (110001, 'The Killers - Sams Town', 1234, 'Ann', 'Smyth', #9/01/06#, #9/10/06#, 'Yes', 2.00)";
addRental2 = "insert into Rental values (120001, 'Mission Impossible 3', 2345, 'John', 'Murphy', #9/02/06#, #9/09/06#, 'No', 0.00)";
addRental3 = "insert into Rental values (130001, 'Need for Special Carbon', 1324, 'James', 'McFadden', #9/03/06#, #9/12/06#, 'Yes', 2.00)";
addRental4 = "insert into Rental values (110002, 'Robbie Williams - Rudebox', 1235, 'Frankie', 'Ferry', #9/04/06#, #9/11/06#, 'No', 0.00)";
addRental5 = "insert into Rental values (120015, 'Prime', 1236, 'Daniel', 'McKimm', #9/05/06#, #9/14/06#, 'Yes', 2.00)";
addRental6 = "insert into Rental values (130015, 'FIFA 07', 2346, 'Stephen', 'Doohan', #9/06/06#, #9/13/06#, 'No', 0.00)";
addRental7 = "insert into Rental values (110009, 'Roxette - Roxette hits', 2347, 'James', 'Ferry', #9/07/06#, #9/16/06#, 'Yes', 2.00)";
addRental8 = "insert into Rental values (120003, 'The Break Up', 2348, 'Liam', 'Cannon', #9/08/06#, #9/15/06#, 'No', 0.00)";
addRental9 = "insert into Rental values (130027, 'Gears of War', 2401, 'Ciaran', 'Ferry', #9/09/06#, #9/18/06#, 'Yes', 2.00)";
addRental10 = "insert into Rental values (110021, 'Scooter - Mind the Gap', 2402, 'Ciaran', 'McGee', #9/10/06#, #9/17/06#, 'No', 0.00)";
try{
stmt = con.createStatement();//Creates a Statement object for sending SQL statements to the database
//statements are allowed to be made once a connection is set up
stmt.executeUpdate(addRental1);
stmt.executeUpdate(addRental2);
stmt.executeUpdate(addRental3);
stmt.executeUpdate(addRental4);
stmt.executeUpdate(addRental5);
stmt.executeUpdate(addRental6);
stmt.executeUpdate(addRental7);
stmt.executeUpdate(addRental8);
stmt.executeUpdate(addRental9);
stmt.executeUpdate(addRental10);
stmt.close();//closes the Statement object
con.close();//terminates the connection with the database
}//end try
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());//returns an SQL error message
}//end catch
}//end maintainRentalDetails
public Demo(){//a constructor
super("Demo Test Frame");//overrides the constructor
setSize(350, 200);//Resizes this component so that it has width of 350 and height of 200
comboBox = new JComboBox();//invokes the class JComboBox
comboBox.addItem("jdbc:odbc:VideoLibrary");//adds the specified item to the end of the scrolling list
qtm = new QueryTableModel();//invokes the class QueryTableModel
JTable table = new JTable(qtm);//a class that shows and changes regular two-dimensional tables of cells
JScrollPane scrollpane = new JScrollPane(table);//a class that provides a scrollable view of a lightweight component
JPanel p1 = new JPanel();//a class that puts the combo box and query field in a panel
p1.setLayout(new GridLayout(3, 2));//Sets the layout manager for this container
p1.add(comboBox);//Appends the specified component to the end of this container
p1.add(new JLabel("Enter your query: "));//Appends the specified component to the end of this container
p1.add(queryField = new JTextField());//Appends the specified component to the end of this container
p1.add(new JLabel("Click here to send: "));//Appends the specified component to the end of this container
JButton jb = new JButton("Search");//a class that is an implementation of a "push" button
jb.addActionListener(new ActionListener(){//Adds an ActionListener to the button
public void actionPerformed(ActionEvent e){
qtm.setHostURL();//invokes the method setHostURL
qtm.setQuery(queryField.getText().trim());//invokes the method setQuery; and returns the text that is presented by this text component and returns a copy of the string, with leading and trailing whitespaces omitted
} );//end addActionListener
p1.add(jb);//Appends the specified component to the end of this container
getContentPane().add(p1, BorderLayout.NORTH);//Returns the content pane
getContentPane().add(scrollpane, BorderLayout.CENTER);//Returns the content pane
}//end Demo
}//end class Demo
import java.sql.*;//Provides the API for accessing and processing data stored in a data source using the Java programming language
import java.io.*;//Provides for system input and output through data streams, serialization and the file system
import java.util.Vector;//provides a class that implements a growable array of objects
import javax.swing.*;//Provides a set of lightweight components that, to the maximum degree possible, work the same on all platforms
import javax.swing.table.*;//Provides classes and interfaces for dealing with javax.swing.JTable
public class QueryTableModel extends AbstractTableModel{
Vector cache;//a class that constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero
int colCount;//a variable that counts the number of columns in the three tables
String[] headers;//a class that represents character strings and all string literals in this program are implemented as instances of the String class
Connection db;//an interface that allows a connection to be made to a database
Statement statement;//an interface that allows executes the given SQL statement, which returns a single ResultSet object
String currentURL;//a variable that allows the URL to be displayed in a combo box
public QueryTableModel(){//a constructor
cache=new Vector();//constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//used by opening a JDBC connection using an URL
}//end try
catch(Exception e){
System.out.println("problem loading the driver ");//an error message
}//end catch
}//end QueryTableModel
public String getColumnName(int i){//Returns the designated column's name
return headers;//returns the name of each column in the three table
}//end getColumnName
public int getColumnCount(){//Returns the number of columns in the column model
return colCount;//returns the number of columns in the three tables
}//end getColumnCount
public int getRowCount(){//Returns the number of rows in this table's model
return cache.size();//returns the number of components in the vector
}//end getRowCount
public Object getValueAt(int row, int col){//Returns the cell value at row and column
return ((String[])cache.elementAt(row))[col];//Returns the component at the specified index
}//end getValueAt
public void setHostURL(){//sets the URL for the database
String url = "jdbc:odbc:VideoLibrary";//a variable that allows a connection to be made to a database called VideoLibrary
closeDB();//invokes the method closeDB()
try{
db=DriverManager.getConnection(url,"","");//tries to create a connection with the database using the DriverManager class
statement=db.createStatement();//Creates a Statement object for sending SQL statements to the database
}//end try
catch(Exception e){
System.out.println("Could not initialize the database.");//an error message
e.printStackTrace();//a Throwable method that prints this throwable and it's backtrace to the standard error stream
}//end catch
}//end setHostURL
public void setQuery(String q){//sets the kind of query that is to be sent to the database
cache=new Vector();//constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero
String s="select * from Product";//a variable that causes all the data that is in the product table to be displayed in a JTable, which also means that all the data that is in both the member and rental tables can also be displayed in a JTable
try{
ResultSet rs=statement.executeQuery(q);//an interface that is used to generate a database result set by executing a statement that queries the database
ResultSetMetaData meta=rs.getMetaData();//an interface that is used to get information about the types and properties of the columns in a ResultSet object
colCount=meta.getColumnCount();//Returns the number of columns in this ResultSet object
headers=new String[colCount];//gets the name of each column in the three tables
for(int h=1;h<=colCount;h++){
headers[h-1]=meta.getColumnName(h);//Get the designated column's name
}//end for
while(rs.next()){
String[] record=new String[colCount];//stores the name of each column in the three tables in memory
for(int i=0;i<colCount;i++){
record[i]=rs.getString(i+1);//Retrieves the value of the designated column in the current row of this ResultSet object as a String
}//end for
cache.addElement(record);//Adds the specified component to the end of this vector, increasing its size by one
}//end while
fireTableChanged(null);//Forwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model
}//end try
catch(Exception e){
cache=new Vector();//constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero
e.printStackTrace();//a Throwable method that prints this throwable and it's backtrace to the standard error stream
}//end catch
}//end setQuery
public void initDB(String url){
try{
db=DriverManager.getConnection(url);//tries to create a connection with the database using the DriverManager class
statement=db.createStatement();//Creates a Statement object for sending SQL statements to the database
}//end try
catch(Exception e){
System.out.println("Could not initialize the database.");//an error message
e.printStackTrace();//a Throwable method that prints this throwable and it's backtrace to the standard error stream
}//end catch
}//end initDB
public void closeDB(){
try{
if(statement!=null){
statement.close();//Releases this Statement object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed
}//end if
if(db!=null){
db.close();//Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be automatically released
}//end if
}//end try
catch(Exception e){
System.out.println("Could not close the current connection.");//an error message
e.printStackTrace();//a Throwable method that prints this throwable and it's backtrace to the standard error stream
}//end catch
}//end closeDB
}//end class QueryTableModelhere's an uncommented version of the code.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.JOptionPane;
import java.sql.*;
public class Demo extends JFrame{
static String url = "jdbc:odbc:VideoLibrary";
static Statement stmt;
static Connection con;
JTextField hostField;
JTextField queryField;
QueryTableModel qtm;
JComboBox comboBox;
public static void main(String args[]){
int choice=-1;
do{
choice=getChoice();
if(choice!=0){
getSelected(choice);
}while(choice!=5);
System.exit(0);
public static int getChoice(){
String choice;
int ch;
choice = JOptionPane.showInputDialog(null,"1. Maintain product details\n"+"2. Maintain member details\n"+"3. Maintain rental details\n"+"4. View product, member and rental details\n"+"5. Log Off\n\n"+"Enter your choice");
ch = Integer.parseInt(choice);
return ch;
public static void getSelected(int choice){
if(choice==1){
maintainProductDetails();
if(choice==2){
maintainMemberDetails();
if(choice==3){
maintainRentalDetails();
if(choice==4){
Demo test = new Demo();
test.setVisible(true);
public static Connection getConnection(){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(java.lang.ClassNotFoundException e){
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
try {
con=DriverManager.getConnection(url,"","");
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
return con;
public static void maintainProductDetails(){
Connection con = getConnection();
String addProduct1, addProduct2, addProduct3, addProduct4, addProduct5, addProduct6, addProduct7, addProduct8, addProduct9, addProduct10;
addProduct1 = "insert into Product values (110001, 'The Killers - Sams Town', 5.00, 'G', 'CD', 2006)";
addProduct2 = "insert into Product values (110002, 'Robbie Williams - Rudebox', 5.00, 'G', 'CD', 2006)";
addProduct3 = "insert into Product values (110003, 'Razorlight - Razorlight', 5.00, 'G', 'CD', 2006)";
addProduct4 = "insert into Product values (110004, 'My Chemical Romance - The Black Parade', 5.00, 'G', 'CD', 2006)";
addProduct5 = "insert into Product values (110005, 'Snow Patrol - Eyes Open', 5.00, 'G', 'CD', 2006)";
addProduct6 = "insert into Product values (110006, 'Scissor Sisters - Ta-Dah!', 5.00, 'G', 'CD', 2006)";
addProduct7 = "insert into Product values (110007, 'Lovesounds - Justin Timberlake', 5.00, 'G', 'CD', 2006)";
addProduct8 = "insert into Product values (110008, 'Director - We thrive on big cities', 5.00, 'G', 'CD', 2006)";
addProduct9 = "insert into Product values (110009, 'Roxette - Roxette hits', 5.00, 'G', 'CD', 2006)";
addProduct10 = "insert into Product values (110010, '***** Cat Dolls - PCD', 5.00, 'G', 'CD', 2006)";
try {
stmt = con.createStatement();
stmt.executeUpdate(addProduct1);
stmt.executeUpdate(addProduct2);
stmt.executeUpdate(addProduct3);
stmt.executeUpdate(addProduct4);
stmt.executeUpdate(addProduct5);
stmt.executeUpdate(addProduct6);
stmt.executeUpdate(addProduct7);
stmt.executeUpdate(addProduct8);
stmt.executeUpdate(addProduct9);
stmt.executeUpdate(addProduct10);
stmt.close();
con.close();
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
public static void maintainMemberDetails(){
Connection con = getConnection();
String addMember1, addMember2, addMember3, addMember4, addMember5, addMember6, addMember7, addMember8, addMember9, addMember10;
addMember1 = "insert into Member values (1234, 'Ann', 'Smyth', 'Upper Killult, Falcarragh, Co. Donegal', '(074)-9135210', '(087)-2030172', #5/11/85#, #5/12/06#)";
addMember2 = "insert into Member values (2345, 'John', 'Murphy', 'Lower Killult, Falcarragh, Co. Donegal', '(074)-9135211', '(087)-2030173', #4/12/85#, #6/13/06#)";
addMember3 = "insert into Member values (1324, 'James', 'McFadden', 'Lower Ardsbeg, Gortahork, Co. Donegal', '(074)-9165314', '(087)-2030171', #4/11/85#, #6/14/06#)";
addMember4 = "insert into Member values (1235, 'Frankie', 'Ferry', 'Ardsmore, Gortahork, Co. Donegal', '(074)-9165325', '(087)-2031234', #6/13/60#, #6/15/06#)";
addMember5 = "insert into Member values (1236, 'Daniel', 'McKimm', 'Ballyness, Falcarragh, Co. Donegal', '(074)-9135212', '(087)-2030184', #5/14/73#, #6/16/06#)";
addMember6 = "insert into Member values (2346, 'Stephen', 'Doohan', 'Ballyness, Falcarragh, Co. Donegal', '(074)-9135213', '(087)-2030185', #6/13/85#, #5/13/06#)";
addMember7 = "insert into Member values (2347, 'James', 'Ferry', 'Meenlaragh, Gortahork, Co.Donegal', '(074)-9165360', '(087)-2031345', #9/12/85#, #5/14/06#)";
addMember8 = "insert into Member values (2348, 'Liam', 'Cannon', 'Derryconner, Gortahork, Co.Donegal', '(074)-9165324', '(087)-2031456', #4/11/86#, #5/15/06#)";
addMember9 = "insert into Member values (2401, 'Ciaran', 'Ferry', 'Brinalack, Gweedore, Co.Donegal', '(074)-9176425', '(087)-2030282', #9/12/85#, #5/16/06#)";
addMember10 = "insert into Member values (2402, 'Ciaran', 'McGee', 'Derrybeg, Gweedore, Co.Donegal', '(074)-9176536', '(087)-2030393', #9/14/85#, #5/18/06#)";
try{
stmt = con.createStatement();
stmt.executeUpdate(addMember1);
stmt.executeUpdate(addMember2);
stmt.executeUpdate(addMember3);
stmt.executeUpdate(addMember4);
stmt.executeUpdate(addMember5);
stmt.executeUpdate(addMember6);
stmt.executeUpdate(addMember7);
stmt.executeUpdate(addMember8);
stmt.executeUpdate(addMember9);
stmt.executeUpdate(addMember10);
stmt.close();
con.close();
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
public static void maintainRentalDetails(){
Connection con = getConnection();
String addRental1, addRental2, addRental3, addRental4, addRental5, addRental6, addRental7, addRental8, addRental9, addRental10;
addRental1 = "insert into Rental values (110001, 'The Killers - Sams Town', 1234, 'Ann', 'Smyth', #9/01/06#, #9/10/06#, 'Yes', 2.00)";
addRental2 = "insert into Rental values (120001, 'Mission Impossible 3', 2345, 'John', 'Murphy', #9/02/06#, #9/09/06#, 'No', 0.00)";
addRental3 = "insert into Rental values (130001, 'Need for Special Carbon', 1324, 'James', 'McFadden', #9/03/06#, #9/12/06#, 'Yes', 2.00)";
addRental4 = "insert into Rental values (110002, 'Robbie Williams - Rudebox', 1235, 'Frankie', 'Ferry', #9/04/06#, #9/11/06#, 'No', 0.00)";
addRental5 = "insert into Rental values (120015, 'Prime', 1236, 'Daniel', 'McKimm', #9/05/06#, #9/14/06#, 'Yes', 2.00)";
addRental6 = "insert into Rental values (130015, 'FIFA 07', 2346, 'Stephen', 'Doohan', #9/06/06#, #9/13/06#, 'No', 0.00)";
addRental7 = "insert into Rental values (110009, 'Roxette - Roxette hits', 2347, 'James', 'Ferry', #9/07/06#, #9/16/06#, 'Yes', 2.00)";
addRental8 = "insert into Rental values (120003, 'The Break Up', 2348, 'Liam', 'Cannon', #9/08/06#, #9/15/06#, 'No', 0.00)";
addRental9 = "insert into Rental values (130027, 'Gears of War', 2401, 'Ciaran', 'Ferry', #9/09/06#, #9/18/06#, 'Yes', 2.00)";
addRental10 = "insert into Rental values (110021, 'Scooter - Mind the Gap', 2402, 'Ciaran', 'McGee', #9/10/06#, #9/17/06#, 'No', 0.00)";
try{
stmt = con.createStatement();
stmt.executeUpdate(addRental1);
stmt.executeUpdate(addRental2);
stmt.executeUpdate(addRental3);
stmt.executeUpdate(addRental4);
stmt.executeUpdate(addRental5);
stmt.executeUpdate(addRental6);
stmt.executeUpdate(addRental7);
stmt.executeUpdate(addRental8);
stmt.executeUpdate(addRental9);
stmt.executeUpdate(addRental10);
stmt.close();
con.close();
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
public Demo(){
super("Demo Test Frame");
setSize(350, 200);
comboBox = new JComboBox();
comboBox.addItem("jdbc:odbc:VideoLibrary");
qtm = new QueryTableModel();
JTable table = new JTable(qtm);
JScrollPane scrollpane = new JScrollPane(table);
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(3, 2));
p1.add(comboBox);
p1.add(new JLabel("Enter your query: "));
p1.add(queryField = new JTextField());
p1.add(new JLabel("Click here to send: "));
JButton jb = new JButton("Search");
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
qtm.setHostURL();
qtm.setQuery(queryField.getText().trim());
p1.add(jb);
getContentPane().add(p1, BorderLayout.NORTH);
getContentPane().add(scrollpane, BorderLayout.CENTER);
import java.sql.*;
import java.io.*;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.*;
public class QueryTableModel extends AbstractTableModel{
Vector cache;
int colCount;
String[] headers;
Connection db;
Statement statement;
String currentURL;
public QueryTableModel(){
cache=new Vector();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(Exception e){
System.out.println("problem loading the driver ");
public String getColumnName(int i){
return headers;
public int getColumnCount(){
return colCount;
public int getRowCount(){
return cache.size();
public Object getValueAt(int row, int col){
return ((String[])cache.elementAt(row))[col];
public void setHostURL(){
String url = "jdbc:odbc:VideoLibrary";
closeDB();
try{
db=DriverManager.getConnection(url,"","");
statement=db.createStatement();
catch(Exception e){
System.out.println("Could not initialize the database.");
e.printStackTrace();
public void setQuery(String q){
cache=new Vector();
String s="select * from Product";
try{
ResultSet rs=statement.executeQuery(q);
ResultSetMetaData meta=rs.getMetaData();
colCount=meta.getColumnCount();
headers=new String[colCount];
for(int h=1;h<=colCount;h++){
headers[h-1]=meta.getColumnName(h);
while(rs.next()){
String[] record=new String[colCount];
for(int i=0;i<colCount;i++){
record[i]=rs.getString(i+1);
cache.addElement(record);
fireTableChanged(null);
catch(Exception e){
cache=new Vector();
e.printStackTrace();
public void initDB(String url){
try{
db=DriverManager.getConnection(url);
statement=db.createStatement();
catch(Exception e){
System.out.println("Could not initialize the database.");
e.printStackTrace();
public void closeDB(){
try{
if(statement!=null){
statement.close();
if(db!=null){
db.close();
catch(Exception e){
System.out.println("Could not close the current connection.");
e.printStackTrace(); -
I need help on bulk inserts....
Hello,
I need help on bulk inserts. I have heard about it but don't know how to do it and how to specify the number of records to be inserted at a time.
Can anyone please help me out?
For example: I would like to insert in my TEST_TABLE a group of data at tha same time...
INSERT INTO TEST_TABLE VALUES ( (1, 'xxx', 'www'), (2, 'yyy', 'hhh'), (3, 'aaa', 'kkk') )
I using Oracle 10g .
Tks!!
Message was edited by:
user532944
Message was edited by:
user532944But I want to insert a group of data at the same time, with one sql instruction...
I don´t know if exists this SQL command...I just know that I can insert
string sqlStmt = "INSERT INTO TESTE VALUES (:x, :x, :x)";
stmt = con->createStatement (sqlStmt);
But and this instruction ?? In MYSql I can do it!!
string sqlStmt = "INSERT INTO TESTE VALUES ((:x, :x, :x), (:x, :x, :x));
Message was edited by:
user532944
Maybe you are looking for
-
Error Message: JBO-26061:Error while opening JDBC connection
JDeveloper 9i was connecting to 9i database (localhost) before and now it is not connecting giving IO Exception. Getting JBO-26061:Error while opening JDBC connection, when run from OC4J. Should we give any path to jdbc classes12.zip? Does it have an
-
HT4557 how come i cant shaire my ipod shuffle to my iphone4
please help i cant shair my ipod shuffle to my iphone 4
-
Images Split After Saving in Camera Raw
I am editing in camera raw from Bridge, I edit, then save. At first the thumbnail remains the same then shortly it becomes 2 half images. Very frustrating!!! I just started this new workflow giving bridge a try and I was very excited about it .. unti
-
Paying $11.99/month instead of $14.99/month
I'm a Spotify premium user in Australia. A friend of mine recently signed up to Spotify premium and is only paying the offered price of $11.99/month. I signed up a few months ago and have noticed that I'm still being charged for $14.99/month. My prem
-
Flash player shows as installed but will not work and is not recognized by anything including adobe
I hve installed flash player(several times) and it will not work. programs using it tell me to install it...but it IS..I can see it in my programs list. I have tried ev everything in adobes suggestions. none work. I cannnot acess my Exfintiy or a