I'm executing the following code and all of the System.out lines are printing fine, not getting any errors. However, when I open the access database, the record has not been inserted. What am I missing? Thanks.
public class JokesToDB
{
public static void main(String args[])
{
String strContrib;
String strJoke;
String strCat;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
Document doc = builder.parse(new File(args[0]));
//Get NodeList of Joke elements
NodeList nlJoke = doc.getElementsByTagName("joke"
;
System.out.println("nlJoke length: " + nlJoke.getLength());
//Capture first Joke element
Element eltJoke = (Element) nlJoke.item(0);
//Capture Joketext element
Element eltJoketext = (Element) XPathAPI.selectSingleNode(eltJoke, "joketext"
;
//Retrieve text node value of joketext
strJoke=eltJoketext.getFirstChild().getNodeValue();
System.out.println("strJoke: " + strJoke);
//Retrieve attribute values from Joke element
strContrib = eltJoke.getAttribute("contributor"
;
System.out.println("strContrib: " + strContrib);
strCat = eltJoke.getAttribute("category"
;
System.out.println("strCat: " + strCat);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"
;
System.out.println("No problem with Class.forName"
;
String url = "jdbc
dbc:AppDev";
Connection con = DriverManager.getConnection(url, "admin", ""
;
System.out.println("No problem with DriverManager.getConnection"
;
Statement stmt = con.createStatement();
System.out.println("No problem with con.createStatement"
;
String strSQL = "INSERT INTO Jokes (Contributor, Joketext, Category) VALUES ('" + strContrib + "', '" + strJoke + "', '" + strCat + "')";
System.out.println("strSQL: " + strSQL);
stmt.execute(strSQL);
System.out.println("No problem with executeUpdate"
;
}
catch (Throwable t){
System.out.println("Error: " + t.getMessage());
}
}
}
public class JokesToDB
{
public static void main(String args[])
{
String strContrib;
String strJoke;
String strCat;
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
Document doc = builder.parse(new File(args[0]));
//Get NodeList of Joke elements
NodeList nlJoke = doc.getElementsByTagName("joke"
System.out.println("nlJoke length: " + nlJoke.getLength());
//Capture first Joke element
Element eltJoke = (Element) nlJoke.item(0);
//Capture Joketext element
Element eltJoketext = (Element) XPathAPI.selectSingleNode(eltJoke, "joketext"
//Retrieve text node value of joketext
strJoke=eltJoketext.getFirstChild().getNodeValue();
System.out.println("strJoke: " + strJoke);
//Retrieve attribute values from Joke element
strContrib = eltJoke.getAttribute("contributor"
System.out.println("strContrib: " + strContrib);
strCat = eltJoke.getAttribute("category"
System.out.println("strCat: " + strCat);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"
System.out.println("No problem with Class.forName"
String url = "jdbc
Connection con = DriverManager.getConnection(url, "admin", ""
System.out.println("No problem with DriverManager.getConnection"
Statement stmt = con.createStatement();
System.out.println("No problem with con.createStatement"
String strSQL = "INSERT INTO Jokes (Contributor, Joketext, Category) VALUES ('" + strContrib + "', '" + strJoke + "', '" + strCat + "')";
System.out.println("strSQL: " + strSQL);
stmt.execute(strSQL);
System.out.println("No problem with executeUpdate"
}
catch (Throwable t){
System.out.println("Error: " + t.getMessage());
}
}
}