Adult webspace - Using JDBC with Java Applications and Applets 82

Using JDBC with Java Applications and Applets 82 output statement, we use the name of the column as defined in the query. There is hidden meaning in that last sentence. In the query we used SELECT * FROM acc_acc we asked for all of the columns from data in the acc_acc table without any row restrictions. The * pulls all of the columns as well as the column names defined in the table. What this means to the ResultSet is that the values can be pulled using the names as declared in the table. Consider the following code: ResultSet rs = statement.executeQuery( “SELECT acc_id, username FROM acc_acc”); rs.next(); System.out.println(rs.getString(”username”)); System.out.println(rs.getString(”password”)); The first output line pulls the username value from the ResultSet. We can again use the name of the column as defined in the table since we ve asked the database to return both the acc_id and username from the table. The second output line will produce a SQLException exception because no password column is defined in the ResultSet. Finally, consider this code: ResultSet rs = statement.executeQuery( “SELECT acc_id, username “User” FROM acc_acc”); rs.next(); System.out.println(rs.getString(”User”)); System.out.println(rs.getString(”username”)); The first output line attempts to pull a column called User from the ResultSet. It will be successful because our SELECT pulled the username column from the table but renamed it as User (which is the column name used in the ResultSet). The second output line in this code example produces a SQLException exception. Primitive Getters Connector/J includes getter methods for all of the primitive types defined within a MySQL table. In this section, we present examples for using each of the methods. Boolean If you are interested in retrieving a column s value as a Java Boolean value, two methods are available: Boolean getBoolean(int columnIndex) Boolean getBoolean(String columnName); As we ve discussed, the task of the getter method is to pull the value from a table column and attempt to convert it to the intended Java type. For the getBoolean()
Note: If you are looking for top 10 and very good webhost to host and run your jsp application check Actions jsp hosting services

Comments are closed.