JDBC-ODBC connectivity

A

ambreen_ssuet

hi

i m facing problem in running tht code
i also followed these stpes in order to connnect java with access

control panel->administrative tool->data sources

ODBC ->from user data sources select MS access data

base-> from the driver list select Driver to database

Access(*.mdb)->Finish ->data source name =employee

(database name)->click on select button from there i

select the database and the path will appear infront

of database->ok->ok



but still the connection was not establishing

code is L

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;


public class app_next extends Applet implements ActionListener {


private String url,userid,pass;
private Connection connect;
private TextArea output;


private Panel labelPanel, fieldsPanel,buttonPanel;
private String labels[] ={"Employee number:","Employee
name:","Salary:","department no:","Manager:", "Job:" , "Hire date:" ,
"Comm:" ,"Department name","Location"};

TextField txtempno, txtename, txtsal, txtdeptno,txtmgr, txtjob,
txthiredate, txtcomm,txtdname,txtloc;

Button insert,delete,update,clear,find,help;




public void init ()
{
//Label Panel
labelPanel = new Panel ();
labelPanel.setLayout (new GridLayout (labels.length, 1));



for (int i = 0; i< labels.length; i ++)
labelPanel.add (new Label (labels , 0) );

//TextField panel
fieldsPanel = new Panel ();
fieldsPanel.setLayout (new GridLayout (labels.length, 2) );

txtempno = new TextField (4);
// txtempno.setEditable (false);
fieldsPanel.add(txtempno);

txtename = new TextField (10);
fieldsPanel.add(txtename);

txtsal = new TextField (2);
fieldsPanel.add(txtsal);

txtdeptno = new TextField (1);
fieldsPanel.add(txtdeptno);

txtmgr = new TextField (1);
fieldsPanel.add(txtmgr);

txtjob = new TextField (7);
fieldsPanel.add(txtjob);

txthiredate = new TextField (4);
fieldsPanel.add(txthiredate);

txtcomm = new TextField (2);
fieldsPanel.add(txtcomm);

txtdname = new TextField (1);
fieldsPanel.add(txtdname);

txtloc = new TextField (5);
fieldsPanel.add(txtloc);


buttonPanel = new Panel ();
buttonPanel.setLayout (new GridLayout () );


insert=new Button("Insert");
// insert.setMnemonic('i');
buttonPanel.add(insert);

delete=new Button("Delete");
buttonPanel.add(delete);

update=new Button("Update");
buttonPanel.add(update);

find=new Button("Find");
buttonPanel.add(find);

clear=new Button("Clear");
buttonPanel.add(clear);

help=new Button("help");
buttonPanel.add(help);
help.addActionListener(this);



this.setLayout (new BorderLayout () );
add ("West",labelPanel);
add ("Center",fieldsPanel);
add ("South",buttonPanel);

try {
url = "jdbc:eek:dbc:employee";
userid="guest";
pass="guest";
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
connect = DriverManager.getConnection (url,userid,pass);
output.append ("connection successful\n");
}
catch (ClassNotFoundException cnfx){
// process ClassNotFoundExceptions here
cnfx.printStackTrace ();
output.append("Connection unsuccessful\n" + cnfx.toString());
}
catch (SQLException sqlex){
// process SQLExceptions here
sqlex.printStackTrace();
output.append("Connection unsucessful\n"+sqlex.toString ());
}

catch (Exception ex) {
// process remaining Exception here
ex.printStackTrace();
output.append(ex.toString());
}

}// END Of INIT METHOD

public void actionPerformed (ActionEvent e){

JOptionPane.showMessageDialog("Click Find to locate a record...");


}

}// END OF CLASS



can any one help me :)
 
S

steve

hi

i m facing problem in running tht code
i also followed these stpes in order to connnect java with access

control panel->administrative tool->data sources

ODBC ->from user data sources select MS access data

base-> from the driver list select Driver to database

Access(*.mdb)->Finish ->data source name =employee

(database name)->click on select button from there i

select the database and the path will appear infront

of database->ok->ok



but still the connection was not establishing

code is L

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;


public class app_next extends Applet implements ActionListener {


private String url,userid,pass;
private Connection connect;
private TextArea output;


private Panel labelPanel, fieldsPanel,buttonPanel;
private String labels[] ={"Employee number:","Employee
name:","Salary:","department no:","Manager:", "Job:" , "Hire date:" ,
"Comm:" ,"Department name","Location"};

TextField txtempno, txtename, txtsal, txtdeptno,txtmgr, txtjob,
txthiredate, txtcomm,txtdname,txtloc;

Button insert,delete,update,clear,find,help;




public void init ()
{
//Label Panel
labelPanel = new Panel ();
labelPanel.setLayout (new GridLayout (labels.length, 1));



for (int i = 0; i< labels.length; i ++)
labelPanel.add (new Label (labels , 0) );

//TextField panel
fieldsPanel = new Panel ();
fieldsPanel.setLayout (new GridLayout (labels.length, 2) );

txtempno = new TextField (4);
// txtempno.setEditable (false);
fieldsPanel.add(txtempno);

txtename = new TextField (10);
fieldsPanel.add(txtename);

txtsal = new TextField (2);
fieldsPanel.add(txtsal);

txtdeptno = new TextField (1);
fieldsPanel.add(txtdeptno);

txtmgr = new TextField (1);
fieldsPanel.add(txtmgr);

txtjob = new TextField (7);
fieldsPanel.add(txtjob);

txthiredate = new TextField (4);
fieldsPanel.add(txthiredate);

txtcomm = new TextField (2);
fieldsPanel.add(txtcomm);

txtdname = new TextField (1);
fieldsPanel.add(txtdname);

txtloc = new TextField (5);
fieldsPanel.add(txtloc);


buttonPanel = new Panel ();
buttonPanel.setLayout (new GridLayout () );


insert=new Button("Insert");
// insert.setMnemonic('i');
buttonPanel.add(insert);

delete=new Button("Delete");
buttonPanel.add(delete);

update=new Button("Update");
buttonPanel.add(update);

find=new Button("Find");
buttonPanel.add(find);

clear=new Button("Clear");
buttonPanel.add(clear);

help=new Button("help");
buttonPanel.add(help);
help.addActionListener(this);



this.setLayout (new BorderLayout () );
add ("West",labelPanel);
add ("Center",fieldsPanel);
add ("South",buttonPanel);

try {
url = "jdbc:eek:dbc:employee";
userid="guest";
pass="guest";
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
connect = DriverManager.getConnection (url,userid,pass);
output.append ("connection successful\n");
}
catch (ClassNotFoundException cnfx){
// process ClassNotFoundExceptions here
cnfx.printStackTrace ();
output.append("Connection unsuccessful\n" + cnfx.toString());
}
catch (SQLException sqlex){
// process SQLExceptions here
sqlex.printStackTrace();
output.append("Connection unsucessful\n"+sqlex.toString ());
}

catch (Exception ex) {
// process remaining Exception here
ex.printStackTrace();
output.append(ex.toString());
}

}// END Of INIT METHOD

public void actionPerformed (ActionEvent e){

JOptionPane.showMessageDialog("Click Find to locate a record...");


}

}// END OF CLASS



can any one help me :)


1. you do not need to setup data-sources,, JDBC does not use that crap.
2. you need to use the correct ODBC library for your database. (what database
are you using)
3. your URL is WRONG!!


Seve
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

1. you do not need to setup data-sources,, JDBC does not use that crap.

JDBC ODBC bridge can use DSN's, but does not have to.
2. you need to use the correct ODBC library for your database. (what database
are you using)

The original poster both state he is using Access and that he is using
the correct ODBC driver.
3. your URL is WRONG!!

The URL is correct for using JDBC ODBC bridge with a DSN.

Arne
 
A

aMBREEn...

thank u so much for ur reply
i m using MS access database
can u plz tell me the correct URL???
what is the correct ODBC library for the database?????


hi

i m facing problem in running tht code
i also followed these stpes in order to connnect java with access

control panel->administrative tool->data sources

ODBC ->from user data sources select MS access data

base-> from the driver list select Driver to database

Access(*.mdb)->Finish ->data source name =employee

(database name)->click on select button from there i

select the database and the path will appear infront

of database->ok->ok



but still the connection was not establishing

code is L

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;


public class app_next extends Applet implements ActionListener {


private String url,userid,pass;
private Connection connect;
private TextArea output;


private Panel labelPanel, fieldsPanel,buttonPanel;
private String labels[] ={"Employee number:","Employee
name:","Salary:","department no:","Manager:", "Job:" , "Hire date:" ,
"Comm:" ,"Department name","Location"};

TextField txtempno, txtename, txtsal, txtdeptno,txtmgr, txtjob,
txthiredate, txtcomm,txtdname,txtloc;

Button insert,delete,update,clear,find,help;




public void init ()
{
//Label Panel
labelPanel = new Panel ();
labelPanel.setLayout (new GridLayout (labels.length, 1));



for (int i = 0; i< labels.length; i ++)
labelPanel.add (new Label (labels , 0) );

//TextField panel
fieldsPanel = new Panel ();
fieldsPanel.setLayout (new GridLayout (labels.length, 2) );

txtempno = new TextField (4);
// txtempno.setEditable (false);
fieldsPanel.add(txtempno);

txtename = new TextField (10);
fieldsPanel.add(txtename);

txtsal = new TextField (2);
fieldsPanel.add(txtsal);

txtdeptno = new TextField (1);
fieldsPanel.add(txtdeptno);

txtmgr = new TextField (1);
fieldsPanel.add(txtmgr);

txtjob = new TextField (7);
fieldsPanel.add(txtjob);

txthiredate = new TextField (4);
fieldsPanel.add(txthiredate);

txtcomm = new TextField (2);
fieldsPanel.add(txtcomm);

txtdname = new TextField (1);
fieldsPanel.add(txtdname);

txtloc = new TextField (5);
fieldsPanel.add(txtloc);


buttonPanel = new Panel ();
buttonPanel.setLayout (new GridLayout () );


insert=new Button("Insert");
// insert.setMnemonic('i');
buttonPanel.add(insert);

delete=new Button("Delete");
buttonPanel.add(delete);

update=new Button("Update");
buttonPanel.add(update);

find=new Button("Find");
buttonPanel.add(find);

clear=new Button("Clear");
buttonPanel.add(clear);

help=new Button("help");
buttonPanel.add(help);
help.addActionListener(this);



this.setLayout (new BorderLayout () );
add ("West",labelPanel);
add ("Center",fieldsPanel);
add ("South",buttonPanel);

try {
url = "jdbc:eek:dbc:employee";
userid="guest";
pass="guest";
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
connect = DriverManager.getConnection (url,userid,pass);
output.append ("connection successful\n");
}
catch (ClassNotFoundException cnfx){
// process ClassNotFoundExceptions here
cnfx.printStackTrace ();
output.append("Connection unsuccessful\n" + cnfx.toString());
}
catch (SQLException sqlex){
// process SQLExceptions here
sqlex.printStackTrace();
output.append("Connection unsucessful\n"+sqlex.toString ());
}

catch (Exception ex) {
// process remaining Exception here
ex.printStackTrace();
output.append(ex.toString());
}

}// END Of INIT METHOD

public void actionPerformed (ActionEvent e){

JOptionPane.showMessageDialog("Click Find to locate a record...");


}

}// END OF CLASS



can any one help me :)


1. you do not need to setup data-sources,, JDBC does not use that crap.
2. you need to use the correct ODBC library for your database. (what database
are you using)
3. your URL is WRONG!!


Seve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top