Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 

An interface to demonstrate Java-odbc (Applets)

Custom Search
An interface to demonstrate Java-odbc (Applets)

[ Return to Shlurrrpp......Java ]




Mini - interface to access the Databases from Java

 


The jetconnect software has been downloaded form http://www.xdb.com . To understand the basics you can flip over to the previous page.

 


zzz.java

 



import jet.connect.*;
import java.awt.*;
import java.applet.*;
import java.util.*;

public class zzz extends Applet
{
 Panel p1,p2,p3,p4,p5,p6,p7,p8;
 Panel q,q1,q2;
 Panel r1,r2,r3,r4,r5;
 Panel o1,o2;
 TextField t1,t2,t3,t4,t5,t6;
 List x1;
 Button b1,b2,b3,b4,b5,b6,b7,b8;
 List l1,l2,l3,l4,l5,l6,l9;
 Label a1,a11,a2,a3,a4,a5,a6,a7;
 Label a12,a13,a14;
 DbEnv e;
 DbDbc c;
 DbStmt s;
 DbInteger i;
 DbColDesc l;
 char c1[];
 String g;
 String h;
 String s1,s2,s3,s4,s5,s6,s7,s8,s9;
 String ss1,ss2;
 int n,n1,n2,n3,n4,ctr,n5,n6,n7;
 int ii;
 DbDataSource d;
 DbDriver d1;
 Dimension dd,dd1,dd2;
 boolean a;
 DbChar b;
 DbChar aa,bb;
 DbInteger cc;


 StringTokenizer st1;

 public void init()
 {
 e = DbEnv.SQLAllocEnv();
 

 
 l = new DbColDesc();
 b = new DbChar(200);
 setLayout(new GridLayout(4,1));
 aa = new DbChar(100);
 bb = new DbChar(100);
 cc = new DbInteger();
 ctr = 1;
  ii = 0;
 // **************************************

 p1 = new Panel();
 p1.setLayout(new FlowLayout(0));
 b4 = new Button("CONNECT DSN....");
 p1.add(b4);

 q1 = new Panel();
 q1.setLayout(new BorderLayout());
 b1 = new Button("        DataSources................(Drivers)                ");
 l1 = new List(4,false);

 q1.add("North",b1);
 q1.add("Center",l1);

 p1.add(q1);


 b2 = new Button("            Installed         Drivers               ");
 l2 = new List(4,false);
 q2 = new Panel();
 q2.setLayout(new BorderLayout());
 q2.add("North",b2);
 q2.add("Center",l2);
 
 p1.add(q2);


 add(p1);

 //    ***********************
 p2 = new Panel();
 p2.setLayout(new FlowLayout(0));
 r1 = new Panel();
 r1.setLayout(new BorderLayout());
 a1 = new Label ("Data Source Name");
 t1 = new TextField(15);
 t1.disable();
 b6 = new Button("Display Columns");
 r1.add("North",a1);
 r1.add("Center",t1);
 r1.add("South",b6);
 b6.disable();
 p2.add(r1);

 r4 = new Panel();
 r4.setLayout(new BorderLayout());
 a5 = new Label("Table Names -DSN");
 l3 = new List(4,false);

 r4.add("North",a5);
 r4.add("Center",l3);
 p2.add(r4);

 r2 = new Panel();
 r2.setLayout(new BorderLayout());
 a12 = new Label("Column Names ");
 l4 = new List(4,false);
 r2.add("North",a12);
 r2.add("Center",l4);
 p2.add(r2);

 r3 = new Panel();
 r3.setLayout(new BorderLayout());
 a13 = new Label("Column Types");
 l5 = new List(4,false);
 r3.add("North",a13);
 r3.add("Center",l5);
 p2.add(r3);
 
 r5 = new Panel();
 r5.setLayout(new BorderLayout());
 a14 = new Label("Column Width");
 l9 = new List(4,false);
 r5.add("North",a14);
 r5.add("Center",l9);
 p2.add(r5);


 add(p2);

//  ******************

 p3 = new Panel();
 p3.setLayout(new BorderLayout());

 a3 = new Label("     SQL statement - Insert , Update , Delete ");
 p3.add("North",a3);
 o1 = new Panel();
 o1.setLayout(new FlowLayout(0,25,10));
 t2 = new TextField(70);
 b3 = new Button("Execute SQL");
 b3.disable();

 o1.add(b3);
 o1.add(t2);

 p3.add("Center",o1);
 o2 = new Panel();
 o2.setLayout(new FlowLayout(0));
 a6 = new Label ("No. of records  affected"); 
 t3 = new TextField(5);
 a7 = new Label("Total no. of records in the table");
 t6 = new TextField(5);
 o2.add(a6);
 o2.add(t3);
 o2.add(a7);
 o2.add(t6);

 p3.add("South",o2);
 add(p3);

// ***********

 p7 = new Panel();
 p7.setLayout(new BorderLayout());
 p8 = new Panel();
 p8.setLayout(new FlowLayout(0,22,10));
 t4 = new TextField(70);
 b5 = new Button("Execute Select");
 p8.add(b5);
 b5.disable();
 p8.add(t4);
 p7.add("North",p8);
 x1 = new List(6,false);
 p7.add("Center",x1);
 add(p7);
 }
 
 public boolean handleEvent (Event v)
 {
 super.handleEvent(v);
 if(v.target instanceof TextField)
 {
  s2 = t2.getText();
  n1 = s2.length();
  if ( n1 > 0)
  b3.enable();
  else
  b3.disable();
  b5.enable();
 }

 return false;
}


 public boolean action (Event v,Object o)
 {
 if ("Display Columns".equals(o))
 {

 ii =  0;
 t3.setText("    ");
 t6.setText("    ");
 n = l4.countItems();
 for(int i = 0; i<n; i++)
 l4.delItem(0);

 n = l5.countItems();
 for(int i = 0; i<n; i++)
 l5.delItem(0);

 n = l9.countItems();
 for(int i = 0; i<n; i++)
 l9.delItem(0);

 n = x1.countItems();
 for(int i = 0; i<n; i++)
 x1.delItem(0);


 s8 = l3.getSelectedItem();
 s = c.SQLAllocStmt();
 a = s.SQLColumns(null,null,null,null);
 while (s.SQLFetch())
 {
  s.SQLGetData(3,aa);
  s.SQLGetData(4,bb);
  s.SQLGetData(5,cc);

  if (s8.equals(aa.toString()))
  {
  l4.addItem(bb.toString());
  n3 = cc.intValue();
 if (n3 == Db.SQL_CHAR)
   s5="CHAR";
 if (n3 == Db.SQL_VARCHAR)
   s5="VARCHAR";
 if (n3 == Db.SQL_SMALLINT)
   s5="SMALLINT" ;
 if (n3 == Db.SQL_INTEGER)
   s5="INTEGER";
 if (n3 == Db.SQL_DECIMAL)
   s5="DECIMAL";
 if (n3 == Db.SQL_NUMERIC)
   s5="NUMERIC";
 if (n3 == Db.SQL_REAL)
   s5="REAL" ;
 if (n3 == Db.SQL_FLOAT)
   s5="FLOAT";
 if (n3 == Db.SQL_DOUBLE)
   s5="DOUBLE";
 l5.addItem(s5);
 }
 }
 l4.select(0);
 l5.select(0);
 s.SQLFreeStmt(Db.SQL_DROP);

 s = c.SQLAllocStmt();
 s9 = "Select * from " + s8 ;
 s.SQLExecDirect(s9);
 n6=s.SQLNumResultCols().intValue();
 for(int i = 1; i <= n6 ; i++)
 {
  s.SQLDescribeCol(i,l);
  n7 = l.getPrecision();
  l9.addItem(".."+n7);
 }
 s.SQLFreeStmt(Db.SQL_DROP);

 s = c.SQLAllocStmt();
 s.SQLExecDirect(s9);
 t6.setText("  ");
 while (s.SQLFetch())
 {
 ii++;
 }
 t6.setText(".."+ii);
 s.SQLFreeStmt(Db.SQL_DROP);
 }

 if ("        DataSources................(Drivers)                ".equals(o))
 {
 b1.disable();
 n = l1.countItems();
 for(int i = 0; i<n; i++)
 l1.delItem(0);
 d=e.SQLDataSources(Db.SQL_FETCH_FIRST);
 g=d.getDSN();
 h = d.getDescription();
 ss1 = g+"......"+h;
 l1.addItem(ss1);
 d=e.SQLDataSources(Db.SQL_FETCH_NEXT);
 while(d != null)
 {
 g=d.getDSN();
 h = d.getDescription();
 ss1 = g+"......"+h;
 l1.addItem(ss1);
 d=e.SQLDataSources(Db.SQL_FETCH_NEXT);
 }
  l1.select(0);
 }
 if("            Installed         Drivers               ".equals(o))
 {
 b2.disable();
 n = l2.countItems();
 for(int i = 0; i<n; i++)
 l2.delItem(0);
 d1=e.SQLDrivers(Db.SQL_FETCH_FIRST);
 g=d1.getDriverDesc();

 l2.addItem(g);
 d1=e.SQLDrivers(Db.SQL_FETCH_NEXT);
 while(d1 != null)
 {
 g=d1.getDriverDesc();
 l2.addItem(g);
 d1=e.SQLDrivers(Db.SQL_FETCH_NEXT);
 }
 }
 if ("CONNECT DSN....".equals(o))
 {
 if (ctr > 1)
 {
 c.SQLDisconnect();
 c.SQLFreeConnect();
 }
 c=e.SQLAllocConnect();
 int y = l1.getSelectedIndex();
 if (y >= 0)
 {
 b6.enable();

 n = l3.countItems();
 for(int i = 0; i<n; i++)
 l3.delItem(0);

 n = l4.countItems();
 for(int i = 0; i<n; i++)
 l4.delItem(0);

 n = l5.countItems();
 for(int i = 0; i<n; i++)
 l5.delItem(0);

 n = l9.countItems();
 for(int i = 0; i<n; i++)
 l9.delItem(0);

 n = x1.countItems();
 for(int i = 0; i<n; i++)
 x1.delItem(0);

 t2.setText("");
 t4.setText("");
 t2.setText("");
 t6.setText("");
 s1 =  l1.getSelectedItem();
 n5 = s1.length();
 st1 = new StringTokenizer(s1,".");
 ss2 = st1.nextToken();

 t1.setText(ss2);
 c.SQLConnect(ss2,"","");
 ctr = 2;
 s = c.SQLAllocStmt();
 a = s.SQLTables(null,null,null,"TABLE");
 while (s.SQLFetch())
 {
  s.SQLGetData(3,aa);
  l3.addItem(aa.toString());
 }
 l3.select(0);
 s.SQLFreeStmt(Db.SQL_DROP);
 //b4.disable();

 }
 }
 if("Execute SQL".equals(o))
 {

  s2 = t2.getText();
  if (s2.length() > 0)
  {
  s= c.SQLAllocStmt() ;
  s.SQLExecDirect(s2);
  i=s.SQLRowCount();

  s3=".."+i.toString();
  t3.setText(s3);
  s.SQLFreeStmt(Db.SQL_DROP);
 ii=0 ;
 s = c.SQLAllocStmt();
 s9 = "Select * from " + s8 ;
 a = s.SQLExecDirect(s9);
 t6.setText("  ");
 while (s.SQLFetch())
 {
 ii++;
 }
 t6.setText(".."+ii);
 s.SQLFreeStmt(Db.SQL_DROP);
 }
 }


 if("Execute Select".equals(o))
 {
 s6=t4.getText();
 if (s6.length() > 0)
 {
 s = c.SQLAllocStmt();
 a = s.SQLExecDirect(s6);
 n4=s.SQLNumResultCols().intValue();
 n = x1.countItems();
 for(int i = 0; i<n; i++)
 x1.delItem(0);

 while (s.SQLFetch())
 {
 s7 = new String();
 for( int ii = 1; ii <= n4; ii++)
 {
  s.SQLGetData(ii,b);
  if ( ii > 1)
  s7=s7+",";
  s7=s7+b.toString() ;
 }
  x1.addItem(s7);
 }
 s.SQLFreeStmt(Db.SQL_DROP);
 }
 }
 return false;
 }
}

The expalnations to these pages will be put up as soon as possible. Thanks for visiting this page and very soon we will come with new simplified programs explaining this concept in greater detail. Visit our main page Vijay Mukhi's Technology Cornucopia and please tell us what you feel about the tutorials.

Email your comments, feedback, suggestions et al to us .



[ Return to Shlurrrpp......Java ]


Top 10 read Java Articles
 Get free "1000 Java Tips eBook"

 Java Calendar and Date: good to know facts and code examples

 Array vs ArrayList vs LinkedList vs Vector: an excellent overview and examples

 How can I convert any Java Object into byte array? And byte array to file object

 The Java Lesson 1: What is Java?

 How do I compare two dates and times, date between dates, time between times and

 Maven vs Ant or Ant vs Maven?

 How to open, read, write, close file(s) in Java? Examples on move, rename and de

 Java Array

 Java: JLabel font and color


[ More in News Section ]
Java Lessons

The Java Lesson 1:
What is Java?
The Java Lesson 2:
Anatomy of a simple Java program
The Java Lesson 3:
Identifiers and primitive data types
The Java Lesson 4:
Variables, constants, and literals
The Java Lesson 5:
Arithmetic operations, conversions, and casts
The Java Lesson 6:
Boolean expressions and operations
The Java Lesson 7:
Bitwise operations
The Java Lesson 8:
Flow control with if and else
The Java Lesson 9:
switch statements
The Java Lesson 10:
for, while, and do-while statements
The Java Lesson 11:
Using break and continue
The Java Lesson 12:
Class methods and how they are called
The Java Lesson 13:
Using the Math class
The Java Lesson 14:
Creating and calling custom class methods
The Java Lesson 15:
Overloading class methods
The Java Lesson 16:
An introduction to objects and object references
The Java Lesson 17:
The String class
The Java Lesson 18:
The StringBuffer class
The Java Lesson 19:
Initializing and processing arrays of primitives
The Java Lesson 20:
Initializing and processing arrays of objects
The Java Lesson 23:
Inheritance and overriding inherited methods
The Java Lesson 24:
abstract classes and polymorphism
The Java Lesson 25:
Interfaces, instanceof, and object conversion and casting
The Java Lesson 26:
Introduction to graphical programming and the java.awt packa
The Java Lesson 27:
The Component class
The Java Lesson 28:
Containers and simple layout managers
The Java Lesson 29:
The Color and Font classes
The Java Lesson 30:
Drawing geometric shapes
The Java Lesson 31:
Choice, List, and Checkbox controls
The Java Lesson 32:
Using the Scrollbar graphical control
The Java Lesson 33:
Menus and submenus
The Java Lesson 34:
An introduction to applets and the Applet class
The Java Lesson 35:
Essential HTML to launch an applet and pass it parameters
The Java Lesson 36:
Mouse event processing
Java Lesson 37:
Menus and submenus
Java Lesson 38:
The WindowListener interface and the WindowAdapter class
Java Lesson 39:
An introduction to GridBagLayout
Java Lesson 40:
An introduction to the Java Collections API
Java Lesson 41:
Exception handling with try, catch, and finally blocks
Java Lesson 42:
Claiming and throwing exceptions
Java Lesson 43:
Multithreading, the Thread class, and the Runnable interface
Java Lesson 44:
An introduction to I/O and the File and FileDialog classes
Java Lesson 45:
Low-level and high-level stream classes
Java Lesson 46:
Using the RandomAccessFile class
Java Lessons by
Joh Huhtala: Update

Latest articles
 Java Profiler JProbe to Resolve Performance Problems Faster

 SSL with GlassFish v2, page 5

 SSL with GlassFish v2, page 4

 SSL with GlassFish v2, page 3

 SSL with GlassFish v2, page 2

 The Java Lesson 2: Anatomy of a simple Java program, page 2

 New site about Java for robots and robotics: both software and hardware.

 Exceptions -III: What's an exception and why do I care?

 Exceptions -II: What's an exception and why do I care?

 Exceptions: What's an exception and why do I care?

 Double your Java code quality in 10 minutes, here is receipt

 Murach's Java Servlets and JSP

 How to get ascii code from a char in Java?

 Can we just try without catch? Yes!

 Make Tomcat page load faster

 Make your Tomcat More secure - limit network address for certain IP addresses

 New Java book online starts now here...

 Implementing RESTful Web Services in Java

 Firefox trimming from 1 GB to 40 Mb with many tabs opened

 SSL with GlassFish v2

 My request to replublish Tech Tips

 Search JavaFAQ.nu site here

 New Advanced Installer for Java 6.0 brings XML updates and imports 3rd party MSI

 EJB programming restrictions

 Maven vs Ant or Ant vs Maven?

 Why Java does not use default value which it should?

 How to unsign signed bytes in Java - your guide is here

 The Java Lesson 3: Identifiers and primitive data types. Page 2

 The Java Lesson 7: Bitwise operations with good examples, click here! Page 4

 The Java Lesson 7: Bitwise operations with good examples, click here! Page 3


[ More in News Section ]


Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy