| Archives Threads we can't stand to throw away. | 
07-24-2001, 12:20 PM
|  | ArcAngle | | Join Date: Jul 2000 Location: taking a nap
Posts: 3,604
| | java homework help please! | | You are all my last resort before I commit hari kari all over my prof's laptop.
The assignment is to create, access, and do all kinds of other stuff with a database.
I created the data base. Easy enough. I can even access it in access.
This thing even compiles and everything!
But! When I run the extract program I get this message. Data source name not found and no default driver specified
Now, I went to sun.java.com and looked all of this up, scoured the message boards, etc. and found this explanation: ODBC DSN (data source name) needs to be configured on the client machine
Well, as the client machine (me) is the same as the source machine (me), I thought that was what I was doing when I went into the database manager in the control panel and created the gwizflap thing.
What am I missing here?
Lynne | 
07-24-2001, 12:35 PM
| | | A little code here would help.
Fortunately for you, I've been doing lots of database programming with Java lately.
Go ahead and post the code here. Maybe we can teach lots of other people about Java too! I can see it now... Hadassahchana becomes a programmer! News at 11! | 
07-24-2001, 12:39 PM
|  | ArcAngle | | Join Date: Jul 2000 Location: taking a nap
Posts: 3,604
| | import java.sql.*;
import java.io.*;
import sun.jdbc.odbc.*;
public class Create {
public static void main (String args[]) {
try{
new JdbcOdbcDriver();
String url = "jdbc:odbc:Sales";
String user = "";
String password = "";
Connection con = DriverManager.getConnection(url, user, password);
Statement stmt = con.createStatement();
stmt.executeUpdate("CREATE TABLE Customer (CustomerID VARCHAR(4), CustomerName"
+ " VARCHAR(25), Address VARCHAR(25), BalanceDue CURRENCY)");
stmt.executeUpdate
("INSERT INTO Customer VALUES (1234,'Fred Flynn','22 First St.',1667.00)");
stmt.executeUpdate
("INSERT INTO Customer VALUES (5678,'Darnell Davis','33 Second St.',130.95)");
stmt.executeUpdate
("INSERT INTO Customer VALUES (4321,'Marla Martinez','44 Third St.',0)");
stmt.executeUpdate
("INSERT INTO Customer VALUES (8765,'Carla Kahn','55 Fourth St.', 0)");
stmt.executeUpdate("CREATE TABLE Salesperson (SalespersonID VARCHAR(2),"
+ "SalespersonName VARCHAR(25), Address VARCHAR(25))");
stmt.executeUpdate
("INSERT INTO Salesperson VALUES (12,'Peter Patterson','66 Fifth St.')");
stmt.executeUpdate
("INSERT INTO Salesperson VALUES (98,'Donna Dubarian','77 Sixth St.')");
stmt.executeUpdate("CREATE TABLE Item (ItemNumber VARCHAR(6),"
+ "Description VARCHAR(20), Quantity INTEGER)");
stmt.executeUpdate("INSERT INTO Item VALUES (222222,'radio',32)");
stmt.executeUpdate("INSERT INTO Item VALUES (333333,'television',14)");
stmt.executeUpdate("INSERT INTO Item VALUES (444444,'computer',9)");
stmt.executeUpdate("CREATE TABLE Orders (OrderNumber VARCHAR(4),"
+ " CustomerID VARCHAR(4), SalespersonID VARCHAR(2), OrderDate DATE)");
stmt.executeUpdate("INSERT INTO Orders VALUES (1,1234,12,'Apr 3, 1999')");
stmt.executeUpdate("INSERT INTO Orders VALUES (2,5678,12,'Mar 22, 1999')");
stmt.executeUpdate("INSERT INTO Orders VALUES (3,8765,98,'Feb 19, 1999')");
stmt.executeUpdate("INSERT INTO Orders VALUES (4,1234,12,'Apr 5, 1999')");
stmt.executeUpdate("INSERT INTO Orders VALUES (5,8765,98,'Feb 28, 1999')");
stmt.executeUpdate("CREATE TABLE OrderItem (OrderNumber CHAR(4),"
+ " ItemNumber CHAR(6), Quantity INTEGER, UnitPrice CURRENCY)");
stmt.executeUpdate("INSERT INTO OrderItem VALUES (1,222222,4,27.00)");
stmt.executeUpdate("INSERT INTO OrderItem VALUES (1,333333,2,210.50)");
stmt.executeUpdate("INSERT INTO OrderItem VALUES (1,444444,1,569.00)");
stmt.executeUpdate("INSERT INTO OrderItem VALUES (2,333333,2,230.95)");
stmt.executeUpdate("INSERT INTO OrderItem VALUES (3,222222,3,27.00)");
stmt.executeUpdate("INSERT INTO OrderItem VALUES (3,333333,1,230.95)");
stmt.executeUpdate("INSERT INTO OrderItem VALUES (4,444444,1,569.00)");
stmt.executeUpdate("INSERT INTO OrderItem VALUES (5,222222,2,27.00)");
stmt.executeUpdate("INSERT INTO OrderItem VALUES (5,444444,1,725.00)");
stmt.close();
}catch (Exception e) {e.printStackTrace();}
}
} | 
07-24-2001, 12:40 PM
|  | ArcAngle | | Join Date: Jul 2000 Location: taking a nap
Posts: 3,604
| | And here's the extract code | | import java.sql.*;
import java.io.*;
import sun.jdbc.odbc.*;
public class ExtractInfo {
public static void main (String args[]) {
try{
new JdbcOdbcDriver();
String url = "jdbc:odbc:Sales";
String user = "";
String password = "";
Connection con = DriverManager.getConnection(url, user, password);
Statement stmt = con.createStatement();
String query = "SELECT CustomerName, Address FROM Customer ORDER BY CustomerName";
ResultSet rs = stmt.executeQuery(query);
System.out.println(" Names and Addresses of Customers");
System.out.println("Name\t\tAddress");
while (rs.next())
System.out.println(rs.getString("CustomerName") + '\t' + rs.getString(2));
query = "SELECT * FROM OrderItem "
+ "WHERE ItemNumber = '222222'";
rs = stmt.executeQuery(query);
System.out.println();
System.out.println(" Order items for radios");
System.out.println("OrderNumber\tQuantity\tUnitPrice");
while (rs.next())
System.out.println(rs.getString(1) + "\t\t" + rs.getInt(3)
+ "\t\t$" + rs.getBigDecimal(4,2));
query = "SELECT CustomerName FROM Customer, Orders "
+ "WHERE Customer.CustomerID = Orders.CustomerID "
+ "AND OrderDate = {d '1999-03-22'}";
rs = stmt.executeQuery(query);
System.out.println();
System.out.println(" Customer placing orders on Mar 22, 1999");
while(rs.next())
System.out.println(rs.getString("CustomerName"));
query = "SELECT DISTINCT CustomerName "
+ "FROM Customer, Item, Orders, OrderItem "
+ "WHERE Customer.CustomerID = Orders.CustomerID "
+ "AND Orders.OrderNumber = OrderItem.OrderNumber "
+ "AND OrderItem.ItemNumber = Item.ItemNumber "
+ "AND Description = 'computer'";
rs = stmt.executeQuery(query);
System.out.println();
System.out.println(" Customers ordering computers");
while(rs.next())
System.out.println(rs.getString(1));
query = "SELECT OrderNumber FROM Orders "
+ "WHERE OrderDate BETWEEN {d '1999-04-01'} AND {d '1999-04-30'}";
rs = stmt.executeQuery(query);
System.out.println();
System.out.println(" Order numbers of orders from 4/1/99 to 4/30/99");
while(rs.next())
System.out.println(rs.getString("OrderNumber"));
String sql;
sql = "INSERT INTO Item VALUES ('555555','CD player',10)";
stmt.executeUpdate(sql);
sql = "UPDATE Item SET Quantity = 12 "
+ "WHERE Description = 'CD player'";
stmt.executeUpdate(sql);
System.out.println();
System.out.println(" Added and updated a new item");
System.out.println("Description");
query = "SELECT Description FROM Item";
rs = stmt.executeQuery(query);
while(rs.next())
System.out.println(rs.getString(1));
sql = "DELETE FROM Item WHERE Description = 'CD player'";
stmt.executeUpdate(sql);
query = "SELECT Description FROM Item";
rs = stmt.executeQuery(query);
System.out.println();
System.out.println(" Deleted the new item");
System.out.println("Description");
while(rs.next())
System.out.println(rs.getString(1));
stmt.close();
}catch (Exception e) {e.printStackTrace();}
}
} | 
07-24-2001, 12:41 PM
|  | ArcAngle | | Join Date: Jul 2000 Location: taking a nap
Posts: 3,604
| | I went to control panel > db manager>
And created an access driver and the db is Sales.
Thanks for looking grace.
Lynne | 
07-24-2001, 05:03 PM
| | | **** I'm going to kill this frickin board... I had all of your source nicely formatted, and hit submit, and it didn't go through. Hitting back erased it. Screw it!!!
I think you have a problem in the way that you are loading the database driver.
I've always done it differently. Here are the two methods I've tried: PHP Code: Driver dbDriver = new JdbcOdbcDriver();
Connection dbConnection = dbDriver.getConnection("jdbc: odbc:foo"); // remove the space after the colon
or PHP Code: java.sql.Connection _conn = null;
try {
// Load the driver class
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Define the data source for the driver
String sourceURL = "jdbc: odbc:foo"; // remove the space after the colon
// Create a connection through the DriverManager
_conn = DriverManager.getConnection(sourceURL, "username", "pwd");
| 
07-24-2001, 05:04 PM
| | | also make sure that your jdbc drivers are in your classpath!  | 
07-24-2001, 05:41 PM
|  | ArcAngle | | Join Date: Jul 2000 Location: taking a nap
Posts: 3,604
| | It killed my formatting also | | I promise I had it all tabbed up and everything! Til I submit, and there it goes...
So I use this instead of connection con = ? I can do that.
And ... how do I put the driver into the class path?
Lynne | 
07-24-2001, 06:42 PM
| | | Which OS are you using? Which tool are you running?
Are you running it from the command line or from some tool?
Am I asking enough questions?
BTW, if you want your code to look pretty when you post it here, just surround it with leftbracket+php+rightbracket at the front and a leftbracket+forwardslash+php+rightbracket at the end. | 
07-24-2001, 07:33 PM
|  | ArcAngle | | Join Date: Jul 2000 Location: taking a nap
Posts: 3,604
| | Ok. I'm in windows using jbuilder4 Foundation. The free one that makes you do it all yourself.
When I create a new package it gives me several options. The source code is saved on my a: so that I can carry it around with me. Only I've not been able to do so this time because the Sales folder is on my c:. Now, it also stores a copy of all my code in a folder called jprojects on the c:. And accesses that when looking for the main class. And with jbuilder you HAVE to have a main class or it won't run.
Was that the right answer?
Lynne | 
07-24-2001, 08:15 PM
|  | ArcAngle | | Join Date: Jul 2000 Location: taking a nap
Posts: 3,604
| | PS - | | My servlet is running!! (that's assignment 3)
Now all I have to do is modify the code just a bit, and I can upload the assignment!
Yay me!!
Lynne - who is dreading assignment 4, when I have to access the database through the servlet...
I was BORN to fail java | 
07-24-2001, 08:34 PM
| | | Figures... I finally got the eval version of jBuilder downloaded.
BTW, you should check out VisualAge for Java. It's a pain in the neck sometimes, but it is WAY better than jBuilder. (Review pending)
If you're able to access the database through a java application, you won't have much problem accessing it through a servlet. It's a cakewalk.
I know you can do it!!!!!  | 
07-25-2001, 12:10 AM
|  | ArcAngle | | Join Date: Jul 2000 Location: taking a nap
Posts: 3,604
| |
I still can't access my db through the java application. That's assign2. Was just getting very discouraged, so I went on to assign3.
Ok. Here's my assign2 stupid question -
Should I move the folder with the Sales stuff in it to my a:? That's where all my source code is right now. Would it find the driver then?
Lynne | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | All times are GMT -4. The time now is 12:23 AM. | | | |