473,395 Members | 1,383 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Using the Statement class

Hey I'm trying to execute a simple statement but im getting a java.sql.Statement 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 2266
JosAH
11,448 Expert 8TB
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
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()',...
4
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...
11
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...
6
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...
5
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....
8
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...
5
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...
1
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...
1
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...
5
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.