For 2021 - online Python 3 training - see ((here)).
Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7. We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.
Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc. |
Bean Classes in Java and Java Database Connections
 A class is a bean if it has a constructor that takes no parameters, and if it has methods that start with "get" to read properties, and "set" to set properties. And it's a good idea (!) if the letter after the word get or set is a capital, as this will let it be used within JSP tag libraries. Bean classes may have other methods too ... it's just that they won't be accessible through the bean interface.
 Here's an example of using JDBC to connect to a MySQL database ... from within the code of a bean. Although Java has manager support to connect to databases, it doesn't include the actual support for any specific database - you need to go and download separate packages of classes for that. "How frustrating" you may say (you would be right!) but it means that the Java folks can look after the Java, the database folks can look after the databases, and when a database is updated the user doesn't have to wait for the next release of Java before he can use the new facilities. It also avoids huge arguments in the community about what should (and should not) be included as a standard driver.
So the database manager as shipped is rather like building a hotel without guests, and the individual drivers you load are like the guests. You need the hotel for the guests, but until you have guests it's really not fulfilling any sensible purpose.
Once the classes are there, how does the connectivity work? Here are the steps that we used in the example show here, written during yesterday's course:
Class.forName("xxxx").newInstance();
where xxxx is the driver class
Loads in the driver class into the driver manager
Connection cnamedb = driverManager.getConnection("yyyy");
where yyyy is a pseudoURL which describes the connection
Log in to the appropriate database
Statement bdstate = cnamedb.createStatement();
Get ready to perform an access (query) to the database
ResultSet dbresult = bdstate.executeQuery("zzzz");
where zzzz is the SQL query to be run
Run the actual query - or rather start it, and return an object that will let you iterate through the result
while (dbresult.next()) { Value = dbresult.getString("wwww"); }
where wwww is the field (column) that you want
Extract the data that you want from each row in turn. ... you can now add your code to process the Value variable further ...
Java Database Connections are also covered on our Java Bootcamp and Learning to Program in Java courses. (written 2009-05-02)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles J811 - Java - JDBC - Relational Database Access [515] MySQL - an FAQ - (2005-12-03) [2861] MySQL and Java - connectivity past, present, and future thoughts - (2010-07-09) [3046] Java Beans, tag libraries and JSPs - what and why. - (2010-11-13)
Some other Articles
On the roof of a Melksham Spa HouseFrom the 51773 familyStopping forum spam - control of the signup processNo subject or title?Bean Classes in Java and Java Database ConnectionsClass Loading and Variable Conversion in JavaMy four feet!What is a JSP tag library?Routers, Firewalls and multilayer serversRouting Network Traffic - Proxies, Redirects and DNS
|
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page
This is a page archived from The Horse's Mouth at
http://www.wellho.net/horse/ -
the diary and writings of Graham Ellis.
Every attempt was made to provide current information at the time the
page was written, but things do move forward in our business - new software
releases, price changes, new techniques. Please check back via
our main site for current courses,
prices, versions, etc - any mention of a price in "The Horse's Mouth"
cannot be taken as an offer to supply at that price.
Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).
|
|