Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

gsl.sql.driv

 
sunil ingalagi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please tell me what kind of package is gsl.sql.driv and a method in that gsl.sql.driv.Driver(); and do i neeed to download any jar file for it?

public QueryTableModel() {
cache = new Vector();
new gsl.sql.driv.Driver();
}

its showing error on 3rd line as package gsl.sql.driv does not exist
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds like a classpath issue, but I'm not sure what this has to do with Swing/AWT/SWT/JFace which is the focus of this forum.
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
True. Moving to Java in General.

As for the class, I haven't been able to find it. Where did you get that piece of code from?
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the OP is referring to the book Java Swing 2nd edition
http://www.java2s.com/Code/Java/Swing-JFC/ResultSetandJTable.htm

PS. One of the authors is listed as Brian Cole who used to visit the Ranch regularly. Haven't seen him lately though.
 
sunil ingalagi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:True. Moving to Java in General.

As for the class, I haven't been able to find it. Where did you get that piece of code from?


actually i want to access database table in jTable. im not able to do this in netbeans by drag n drop so i downloaded some example code

im pasting that code here..


/*
Java Swing, 2nd Edition
By Marc Loy, Robert Eckstein, Dave Wood, James Elliott, Brian Cole
ISBN: 0-596-00408-7
Publisher: O'Reilly
*/
// DatabaseTest.java
//Let's try to make one of these databases work with a JTable for ouptut.
//

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.AbstractTableModel;

public class DatabaseTest extends JFrame {

JTextField hostField;

JTextField queryField;

QueryTableModel qtm;

public DatabaseTest() {
super("Database Test Frame");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(350, 200);

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(new JLabel("Enter the Host URL: "));
p1.add(hostField = new JTextField());
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(hostField.getText().trim());
qtm.setQuery(queryField.getText().trim());
}
});
p1.add(jb);
getContentPane().add(p1, BorderLayout.NORTH);
getContentPane().add(scrollpane, BorderLayout.CENTER);
}

public static void main(String args[]) {
DatabaseTest tt = new DatabaseTest();
tt.setVisible(true);
}
}

//QueryTableModel.java
//A basic implementation of the TableModel interface that fills out a Vector of
//String[] structures from a query's result set.
//

class QueryTableModel extends AbstractTableModel {
Vector cache; // will hold String[] objects . . .

int colCount;

String[] headers;

Connection db;

Statement statement;

String currentURL;

public QueryTableModel() {
cache = new Vector();
new gsl.sql.driv.Driver();
}

public String getColumnName(int i) {
return headers[i];
}

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) {
if (url.equals(currentURL)) {
// same database, we can leave the current connection open
return;
}
// Oops . . . new connection required
closeDB();
initDB(url);
currentURL = url;
}

// All the real work happens here; in a real application,
// we'd probably perform the query in a separate thread.
public void setQuery(String q) {
cache = new Vector();
try {
// Execute the query and store the result set and its metadata
ResultSet rs = statement.executeQuery(q);
ResultSetMetaData meta = rs.getMetaData();
colCount = meta.getColumnCount();

// Now we must rebuild the headers array with the new column names
headers = new String[colCount];
for (int h = 1; h <= colCount; h++) {
headers[h - 1] = meta.getColumnName(h);
}

// and file the cache with the records from our query. This would
// not be
// practical if we were expecting a few million records in response
// to our
// query, but we aren't, so we can do this.
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); // notify everyone that we have a new table.
} catch (Exception e) {
cache = new Vector(); // blank it out and keep going.
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();
}
}
}
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nobody will read that much unformatted code without code tags. Please use the "edit" button to add them to the code. It will of course tell you in the book where to find that package.
 
Bill Hoke
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gsl.sql.driv solution!
gsl.sql.driv.Driver() solution!

I too have been searching the internet trying to find references to
gsl.sql.driv and gsl.sql.driv.Driver() in order to allow this program
to run properly. As a 'greenhorn' I was interested in the
QueryTableModel implementation of this program as a learning
exercise. Google searching for many hours took me to some far
off reaches of the internet and the JAVA world. As a result I was
able through trial and error to piece together a solution.
I'll present a solution and a discussion:

1. Solution:

Code problem:
/*
Java Swing, 2nd Edition
By Marc Loy, Robert Eckstein, Dave Wood, James Elliott, Brian Cole
ISBN: 0-596-00408-7
Publisher: O'Reilly
*/
// DatabaseTest.java
//Let's try to make one of these databases work with a JTable for ouptut.
//
...
public QueryTableModel() {
cache = new Vector();
new gsl.sql.driv.Driver();
} ...

a. Go to: http://jdbc.postgresql.org/download/
download: jdbc7.0-1.1.jar

b. Actual file downloaded will be jdbc7.0-1.1.zip
unzip to a directory of your choice.

c. Copy these two files:
Driver.class
DriverClass.class
to the same directory where your
JAVA program is located.

d. Modify your code as follows:
change: new gsl.sql.driv.Driver();
to:
try{
new org.postgresql.Driver();
}catch(Exception ee){
System.out.println("Could not use Driver.");
}

e. Compile your program.
You may see the following results or something similar to:
Note: C:\Program Files\Xinox Software\JCreatorV3 LE\MyProjects\DatabaseTest
\DatabaseTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

f. Run your program and see your results displayed!


2. Discussion:

a. SQL/JDBC part:

In searching I began to notice references to PostgreSQL.jar,
pgjdbc2.jar, and postgresql (www.postgresql.org). I also learned
that some of these drivers work with both MySQL & MS-Access databases.
For my testing, I'm using MS-Access 2007.

I saved the following page which turned out to be key by showing
that jdbc7.0-1.1.jar works and that there were problems with other
related jar's.

> # wrapper.classpath=/java/org/postgresql/pg71/jdbc7.0-1.1.jar
> wrapper.classpath=/java/org/postgresql/pg71/jdbc7.1-1.2.jar works

(from: http://archives.postgresql.org/pgsql-jdbc/2002-08/msg00258.php)

I downloaded 'pgjdbc2.jar' and 'jdbc7.0-1.1.jar(actual zipfile)'.
I first used 'pgjdbc2.jar' with no luck.
I then used 'jdbc7.0-1.1.jar(extracted)' with no luck.

I modified classpath to be sure JAVA 'saw' each file with no luck.

b. JAVA Packaging:

First, I looked into JAVA packaging, having no prior experience with it, to
see if I could build some sort of package for these files to use in
my program with an 'Import' statement. Since there were so many
options I decided against it.

Next I looked for jar extraction programs to get 'inside' of the 'pgjdbc2.jar'
file. That appeared too complicated for me as well.
I also looked for JAVA class decompiling programs to see if I could
get 'inside' of the 'Driver.class' file. I decided against that as there was
a cost associated with the program and you might not get the key info
you are looking for.
But, I did learn and read about the meta information in the 'META-INF'
directory of 'jdbc7.0-1.1.jar(extracted)'. That is where I found the
information regarding:

org.postgresql.Driver();

The file \META-INF\MANIFEST.MF can be opened as a text file and shows:

Name: org/postgresql/Driver.class
Digest-Algorithms: SHA MD5
SHA-Digest: GsTAODvchjM/lcGlu/lTtYcHFlo=
MD5-Digest: bJDjpfFR3EoftUi7V+JV4Q==

and

Name: org/postgresql/DriverClass.class
Digest-Algorithms: SHA MD5
SHA-Digest: gF34WNw7QLEGCXn9rtEgf4IsaJo=
MD5-Digest: Qe+B6gzfDLRTcU6+SNOT+w==

I noticed the reference was similar to the problem line:
new gsl.sql.driv.Driver();

So I replaced the line with: org.postgresql.Driver();

c. Continued trial:

At first that didn't help so I then copied the Driver.class and
the DriverClass.class (I copied this as I didn't know if the two
classes were somehow dependent upon each other) to the
same directory as my JAVA program.

I compiled the program and it almost worked at least I
had gone further than at any other time before.

The SQL warning then appeared. I googled that. After reviewing
enough google references, I decided to run the program.
It worked!

d. Comments:

- I'm posting this as I couldn't find a solution anywhere on the internet.
Hopefully this helps others that may be looking for an answer.

- If anyone has suggestions as to how I could have done this without
placing the Driver.Class file into the directory where my program
was, I'd be glad to see and learn.

- Comments or suggestions are welcome.

- 'Experience is what you get when you didn't get what you were
looking for' - sign at Jimmy Johns in College Park

Thanks very much, Bill

 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Bill!

I see some issues in your post.

Bill Hoke wrote: a. Go to: http://jdbc.postgresql.org/download/
download: jdbc7.0-1.1.jar

b. Actual file downloaded will be jdbc7.0-1.1.zip
unzip to a directory of your choice.

c. Copy these two files:
Driver.class
DriverClass.class
to the same directory where your
JAVA program is located.

I wouldn't do that. You can simply add that JAR file to your class path, and all classes can be used. If you don't you may end up missing other classes - not during compile time but during runtime.

b. JAVA Packaging:

First, I looked into JAVA packaging, having no prior experience with it, to
see if I could build some sort of package for these files to use in
my program with an 'Import' statement. Since there were so many
options I decided against it.

Next I looked for jar extraction programs to get 'inside' of the 'pgjdbc2.jar'
file. That appeared too complicated for me as well.
I also looked for JAVA class decompiling programs to see if I could
get 'inside' of the 'Driver.class' file. I decided against that as there was
a cost associated with the program and you might not get the key info
you are looking for.
But, I did learn and read about the meta information in the 'META-INF'
directory of 'jdbc7.0-1.1.jar(extracted)'. That is where I found the
information regarding:

org.postgresql.Driver();

The file \META-INF\MANIFEST.MF can be opened as a text file and shows:

Name: org/postgresql/Driver.class
Digest-Algorithms: SHA MD5
SHA-Digest: GsTAODvchjM/lcGlu/lTtYcHFlo=
MD5-Digest: bJDjpfFR3EoftUi7V+JV4Q==

and

Name: org/postgresql/DriverClass.class
Digest-Algorithms: SHA MD5
SHA-Digest: gF34WNw7QLEGCXn9rtEgf4IsaJo=
MD5-Digest: Qe+B6gzfDLRTcU6+SNOT+w==

I noticed the reference was similar to the problem line:
new gsl.sql.driv.Driver();

So I replaced the line with: org.postgresql.Driver();

Those digests have been created using the keytool program that is shipped with your JDK. You shouldn't just go modifying parts of the manifest like this. Some entries are not a problem (like Main-Class, Class-Path), but others, especially those involved with signing classes, shouldn't be updated manually.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic