• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DataBase drivers in Linux

 
Tom Diamond
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I am trying to learn some things about JDBC these days. I tried a couple of programs on my Win 2K professional platform using Java 2 (JDK 1.3) and the pre-installed "ODBC Data Source Administrator" program.
However, I want to test these things on my Linux platform (SuSe 7.1 professional). Is there an equivalent app to "ODBC Data Source Administrator"?
Any advice would be very helpfull.
Thanx in advance,
Tom.
 
Sean Casey
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which database are you using? I use MySQL and I had to download the appropriate drivers and then include them in my classpath.
 
Tom Diamond
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I don't use a specific database.I just want to create a .dbf file and then update it using Java.
The code I use is the following :
//Start of CreateCoffees.java
import java.sql.*;
public class CreateCoffees {
public static void main(String args[]) {
String url = "jdbc dbc:dBASE Files";
Connection con;
String createString;
createString = "create table COFFEES " +
"(COF_NAME VARCHAR(32), " +
"SUP_ID INTEGER, " +
"PRICE FLOAT, " +
"SALES INTEGER, " +
"TOTAL INTEGER)";
String add1 = "INSERT INTO COFFEES " +
"VALUES ('Colombian', 101, 7.99, 0, 0)";
String add2 = "INSERT INTO COFFEES " +
"VALUES ('Espresso', 150, 9.99, 0, 0)";
String add3 = "INSERT INTO COFFEES " +
"VALUES ('Colombian_Decaf', 101, 8.99, 0, 0)";
String add4 = "INSERT INTO COFFEES " +
"VALUES ('French_Roast_Decaf', 49, 9.99, 0, 0)";

Statement stmt;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url, "", "");
stmt = con.createStatement();
stmt.executeUpdate(createString); //Create dBase file
stmt.executeUpdate(add1); //Modifying...
stmt.executeUpdate(add2);
stmt.executeUpdate(add3);
stmt.executeUpdate(add4);
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}
//End of CreateCoffees.java
This thing creates a table stored in COFFEES.dbf and then adds some data into it.
Watch line 3 :: I say "jdbc dbc:dBASE Files" because the "OBDC Data Source Administrator" program has linked "dBASE Files" with the appropriate driver.
What will I have to write in a Linux platform?
Thanx,
Tom.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic