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.