473,785 Members | 2,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using the Statement class

67 New Member
Hey I'm trying to execute a simple statement but im getting a java.sql.Statem ent is abstract; cannot be instantiated. I just want to execute a simple select statement

Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.sql.Statement;
  3. import java.io.BufferedReader;
  4. import java.io.InputStream;
  5. import java.io.InputStreamReader;
  6. import java.sql.Connection;
  7. import java.sql.DriverManager;
  8. import java.util.ArrayList;
  9.  
  10. /**
  11.  * @date February 9, 2009
  12.  * @author Colin Hanshaw
  13.  */
  14.  
  15. public class ProcessChecker 
  16. {
  17.     String parsedString;
  18.     int counter = 0;
  19.     ArrayList parsedStrings = new ArrayList();
  20.     private static String dbURL = "jdbc:derby://localhost:1527/MyDesk;user=administrator;password=password";
  21.     private static String tableName = "BLOCKEDLIST";
  22.     private static Connection conn = null;
  23.     boolean running = true;
  24.     boolean yesno;
  25.  
  26.  
  27.     public static void main(String[] args) throws Exception
  28.     {
  29.         ProcessChecker checker = new ProcessChecker();
  30.     }
  31.  
  32.     public ProcessChecker()
  33.     {
  34.         createConnection();
  35.         while(running)
  36.         {
  37.             listRunningProcesses();
  38.             getBlockedList();
  39.             //compareLists();
  40.         }
  41.     }
  42.  
  43.     public void getBlockedList()
  44.     {
  45.        Statement stmt = new Statement();
  46.     }
  47.  
  48.     private static void createConnection()
  49.     {
  50.         try
  51.         {
  52.             Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
  53.             conn = DriverManager.getConnection(dbURL);
  54.         }
  55.         catch (Exception except)
  56.         {
  57.             except.printStackTrace();
  58.         }
  59.     }
  60.  
  61.     public void listRunningProcesses()
  62.     {
  63.         try
  64.         {
  65.             Runtime runtime = Runtime.getRuntime();
  66.             String cmds[] = {"cmd", "/c", "tasklist"};
  67.             Process proc = runtime.exec(cmds);
  68.             InputStream inputstream = proc.getInputStream();
  69.             InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
  70.             BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
  71.             String line;
  72.             while ((line = bufferedreader.readLine()) != null)
  73.             {
  74.                parsedString = parseString(line);
  75.                parsedStrings.add(new String(parsedString));
  76.                counter++;
  77.             }
  78.             removeElements();
  79.         }
  80.         catch(Exception ex)
  81.         {
  82.             System.out.println("Tasklist might not exist");
  83.         }
  84.     }
  85.  
  86.     public String parseString(String incString)
  87.     {
  88.         String myParsedString = incString;
  89.         String delims = "[ ]+";
  90.         String[] tokens = incString.split(delims);
  91.         myParsedString = tokens[0];
  92.         return myParsedString;
  93.     }
  94.  
  95.     public void removeElements()
  96.     {
  97.         parsedStrings.remove(0);
  98.         parsedStrings.remove(0);
  99.         parsedStrings.remove(0);
  100.     }
  101. }
  102.  
Feb 9 '09 #1
1 2283
JosAH
11,448 Recognized Expert MVP
Read the API documentation: all of the entities in the JDBC framework are interfaces; a Statement (just as a Connection) is an interface and you can't 'new' interfaces. Check the Connection interface; it can create objects that implement the Statement interface for you.

kind regards,

Jos
Feb 9 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

28
20345
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()', this.pinginterval); - but is there no way to do this without using the literal ObjectName? If I write 'this.methodName()' I get "Line 1 Char 1: Object doesn't support this property or method." in IE, and nothing happens in Firebird.
4
2717
by: Japhy | last post by:
Hello, I'm am pulling data from a mysql db and want to use the data to populate a <ul. Here are relavent parts of my code : $wohdate = mysql_result($wohRS,$wohndx,woh_date); $woh_display .="<li>".$wohdate."</li>" ; $TemplateText = Replace($TemplateText,"@$wohdisplayndx@",$woh_display);
11
6601
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on where the job is running, the job runs sucessfully, PDF files got generated, everything is good. If I scheduled the job to run at the time that I am not logged into the server, Access is not able to print to the printer. The error is pretty...
6
1942
by: newbie | last post by:
I have Class A that implements IDisposable, within this class i have method A that creates a new Sqlconnection object and execute some stored proc, in Class B, I create an instance of Class A object with the using statement.. my question is when my using statement ends Class A's dipose method should be called i think.. but will my Sqlconnection object within Class A Method A be disposed automatically as well?
5
8769
by: charliewest | last post by:
I've implemented the USING statement to ensure that my newly created sql connection closes when my method is finished using it. The USING statement is wrapped in try/catch error handling statement. This works fine. When i try to implement the "SqlTransation" class, the code does not work as the SqlTransation object is out-of-scope in the catch statement, and/or, after the USING statement ends, the sql connection object is automatically...
8
3707
by: J-T | last post by:
I have a class like below I have a couple of questions about that: 1) I like to use "Using statement" when creating an object of this class,so I had to implement IDisposable.Am I doing this right here? 2) Do I have to be worried about those objects I have created in GetPackageNames() ?? for instance making them null afterward or something? 3) This class is in my business layer As you can see I'm using Microsoft.SQLServer.DTSPkg80...
5
5608
by: Andreas Müller | last post by:
Hi, I was wondering, if there is something similar in VB.NET like the using statement in C#. What it does is to automatically call Dispose on the object decrared with in the statement when the block exits. using (MyBoj) { }// MyObj.Dispose is called
1
2618
by: kommaraju | last post by:
iam a starter to db2 & jdbc.i have a servlet program which connects to ibm db2 using jdbc.when i run this using apache tomcat 4.1.34 , it is showing a error message of HTTP STATUS 500 my jdbc program is as follows import java.sql.*; import java.lang.*; import java.io.*; import java.util.*;
1
4378
by: kommaraju | last post by:
iam a starter to db2 & jdbc.i have a servlet program which connects to ibm db2 using jdbc.when i run this using apache tomcat 4.1.34 , it is showing a error message of HTTP STATUS 500 my jdbc program is as follows import java.sql.*; import java.lang.*; import java.io.*; import java.util.*;
5
7144
by: Hillbilly | last post by:
MSDN Remarks "as a rule" the using statement should be used when instantiating objects which inherit IDisposable. Other than the obvious unmanaged objects like the file system example, fonts and the database how else may it be determined which classes and their objects inherit IDisposable? And the remarks imply the using statement is a different and perhaps more efficient way to use objects than try-catch-finally? ...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10151
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.