Java Reference
In-Depth Information
catch(ClassNotFoundException e){
System.err.println(e.getMessage());
}
catch(SQLException e){
System.err.println(e.getMessage());
}
}
public void execute(String SQLCommand){
String url = urlRoot+dbName;
try {
Connection con = DriverManager.getConnection(url);
Statement stmt = con.createStatement();
stmt.execute(SQLCommand);
con.close();
}
catch(SQLException e){
System.err.println(e.getMessage());
}
}
public static void main(String args[]){
DataInserter inserter = new DataInserter();
String SQLCommand = "INSERT INTO CONTACT_INFO "+
"(First_Name,MI,Last_Name,Street,City,State,Zip) "+
"VALUES "+
"('Michael','J','Corleone','86 Horsehead
Blvd','NY','NY','12345');";
inserter.execute(SQLCommand);
}
}
If you compile and execute the example, you should be able to see the new record in your
Contact_info Table. Using a DBMS with a GUI-based management console, you are able to see the
table and its contents when you open the database. With a command line DBMS such as MySQL, you
need to go to the command prompt and type the following command:
SELECT * FROM Contact_Info;
Search WWH ::




Custom Search