Web design course - Chapter 17 . ODBC/JDBC 515 the getConnectionmethod. GetConnectiontakes
Wednesday, April 30th, 2008Chapter 17 . ODBC/JDBC 515 the getConnectionmethod. GetConnectiontakes a string URL as an argument. In the case of MySQL, you provide the URL and credentials for the connection: Connection con; con = DriverManager.getConnection(url, username , password ); Alternatively: Connection con = DriverManager.getConnection(url, username , password ); The basics of handling statements and results The Statementinterface with the JDBC is not an object, but rather, an interface for creating an object that executes statements. You create a Statementobject as follows: Statement stmt = connection.CreateStatement(); With the Statement object created, you use an execute method on the object. There are four execute methods for use with the JDBC: executeQuery(), executeUpdate(), executeBatch(), and execute(). The executeQuery()method is for statements such as SELECT that retrieve values from a database. The executeUpdate() method is used commonly with DDL statements that don t return values but may return a number of rows affected by the operation. Finally, the execute()method is for statements that return greater than one result or count. The executeUpdate() method returns an integer value that contains the number of rows affected by the operation. The results from queries are retrieved using ResultSet. For example: ResultSet result = statement.executeQuery( SELECT * FROM user ); To access the results, use a get method. The basic methods for accessing data are as follows: getBoolean() getByte() getDate() getDouble() getFloat() getInt() getLong() getShort() getString() getTime() getTimestamp()
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.