| November 25, 2025, at 06:06 PM | Hala Skaf-Molli / Main / ExampleOfTableCreationInJDBC |
|
|
ExampleOfTableCreationInJDBCimport java.sql.*; public class CreateTable?{ public static void main (String args[]) {
String url =
"jdbc:oracle:thin:@panoramix.depinfo.uhp-nancy.fr:1521:depinfo";
Connection con;
Statement stmt;
String query ="create table client(nom varchar(20),prenom varchar(20), age int)";
String login="", passwd="";
try {
login=args[0]; passwd=args[1];
} catch (Exception e) {
System.err.println("usage : Create login password");
System.exit(1);}
try {// enregistrement du driver
Class.forName ("oracle.jdbc.driver.OracleDriver?");
} catch(ClassNotFoundException? e){
System.err.print("ClassNotFoundException?");
System.err.println(e.getMessage()); }
try { // connexion et execution de la requete
con = DriverManager?.getConnection (url,login,passwd);
// Create a Statement object so we can submit
// SQL statements to the driver
stmt = con.createStatement ();
stmt.executeUpdate(query);
stmt.close(); // Close the statement
con.close(); // Close the connection
}
catch (SQLException? ex) {
System.err.println (" SQLException? caught: "+ ex.getMessage());
}
}
} |
| Validate the XHTML and CSS of this page. | Page last modified on February 15, 2010, at 05:10 PM | Edit History Print Recent Changes |
|
Powered by PmWiki |
||