JDBC  «Prev 

Code for JDBC connection

JDBC and Java Servlets

Open JDBC Connection
Open JDBC Connection

line 1import the IO classes
line 2-3import the servlet classes
line 4import the SQL classes
line 6define the HelloDatabase class
line 8Declare the member variable to hold the connection reference
line 9this begins our override of init()
line 12delegate the work to the super class
line 13start a try/catch block
line 15load and register the JDBC/ODBC bridge as our JDBC driver
line 16open a connection to the DSN
line 19this exception might be thrown by the Class.forName() call
line 21this message will appear on the console where you started the Web server
line 24the exception might be thrown by the getConnection() call
line 26this message will appear on the console where you started the Web server
line 30this begins our override of destroy()
line 32start a try/catch block
line 34close the database connection
line 36the exception might be thrown by the close() call
line 38this message will appear on the console where you started the Web server
line 42the remainder of the servlet was omitted for space reasons