The Artima Developer Community
Sponsored Link

Java Answers Forum
jdbc:odbc:Sales

1 reply on 1 page. Most recent reply: Jul 31, 2002 6:08 AM by Don Hill

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
chuck

Posts: 9
Nickname: chuckjava2
Registered: Jul, 2002

jdbc:odbc:Sales Posted: Jul 30, 2002 8:09 PM
Reply to this message Reply
Advertisement
I create (Sales.mdb) and use Microsoft Access Driver(*mdb). Then I compile the file below and then run it. It show no errors, but the tables are not created. Does anyone know why? Please help. Thanks

chuck




/* Source: L. Kvasny
* Creates and populates the Sales database
*/

import java.sql.*;
import sun.jdbc.odbc.*;

public class Create {
public static void main (String args[]) {
try{
//Load drivers
new JdbcOdbcDriver();
String url = "jdbc:odbc:Sales";

//Connect to database
String user = "";
String password = "";
Connection con = DriverManager.getConnection(url, user, password);
Statement stmt = con.createStatement();
//Create and load tables
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 (SQLException se){System.out.println("SQL Exception"); }
catch (Exception e) {e.printStackTrace();}
}
}


Don Hill

Posts: 70
Nickname: ssswdon
Registered: Jul, 2002

Re: jdbc:odbc:Sales Posted: Jul 31, 2002 6:08 AM
Reply to this message Reply
Try registering the driver first as :

Class.forName("my.sql.Driver");

if you want to make sure the driver is loaded you can
call DriverManager.getDrivers();
HTH

Flat View: This topic has 1 reply on 1 page
Topic: policy file for applet Previous Topic   Next Topic Topic: screensaver

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use