|
Sponsored Links
Resources
Enterprise Java Research Library
Get Java white papers, product information, case studies and webcasts
|
|
Message #124739
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Good -- if it is supported
Retrieving Auto-Generated KeysUnfortunately, not all JDBC drivers (and DBMS's) support this feature -- like Oracle.Use the Right Data-Type Again, the Oracle database only has the NUMBER data-type -- no INTEGER, BYTE, SHORT, FLOAT, etc.
Good Luck, Avi.
|
|
Message #124748
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Use of parameter Markers
It is true that using parameter markers increases performance but I think it creates maintainability problems. What if order of parameters of stored procedure changes sometime later? Using parameter names makes code readable and maintainable. Unless and until good documentation is done and certain rules for stored procedure modifications are followed, using parameter markers can create problems.
|
|
Message #124771
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Use of parameter Markers
You can use named parameters from JDBC 3.0 (not all drivers support it). Or you can write simple JDBC wrapper that supports named parameters. I wrote one myself and it is easy.
MC
|
|
Message #124772
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
JDBC Tips: Selecting Functions that Optimize Performance
>> Using get Methods Effectively
I relay can't see how column named lookup from result set is expensive. If JDBC driver is implemented well that should be not more than a HashMap lookup. Compared to network serilization and wast object creation in JDBC drivers this is realy nothing.
MC
|
|
Message #124773
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
When will TheServerSide allow post editing ?
Bl..dy typos... >> I relay should be: 'I realy'
When will TheServerSide allow post editing ?
|
|
Message #124792
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Use of parameter Markers
If it is supported, use databaseMetaData to get the columns for a specific procedure and then store the name, index, type and paramtype(IN,OUT,INOUT) of each column grouped into an object stored in a hashmap keyed by the procedure name.
--Calum
|
|
Message #124802
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Using get method effectively
I was just wondering , in a enterprise project where Java developer and database DBA guys are two end, How easy to maintain the coulmn number in your code . I would rather use the column name.
|
|
Message #124808
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Pagination
In general, do not write code that relies on the number of result rows from a query because drivers must fetch all rows in a result set to know how many rows the query will return. What is the best way to do pagination (in web pages) without relying on number of rows?
|
|
Message #124836
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Using get method effectively
I was just wondering , in a enterprise project where Java developer and database DBA guys are two end, How easy to maintain the coulmn number in your code . I would rather use the column name. I found it is not a problem in practice. You can validate coulmn numbers on application startup automaticaly too.
|
|
Message #124837
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Pagination
In general, do not write code that relies on the number of result rows from a query because drivers must fetch all rows in a result set to know how many rows the query will return. What is the best way to do pagination (in web pages) without relying on number of rows? You do not relying on number of rows for pagination if you use something like "LIMIT/OFFSET".
|
|
Message #124843
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Using get method effectively
I was just wondering , in a enterprise project where Java developer and database DBA guys are two end, How easy to maintain the coulmn number in your code . I would rather use the column name. I found it is not a problem in practice. You can validate coulmn numbers on application startup automaticaly too. When you need to change your code, you mean you don't need to know the column number and the order? Automaticaly? How do you make it? I just want to know it.
|
|
Message #124848
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Using get method effectively
I was just wondering , in a enterprise project where Java developer and database DBA guys are two end, How easy to maintain the coulmn number in your code . I would rather use the column name. I found it is not a problem in practice. You can validate coulmn numbers on application startup automaticaly too. When you need to change your code, you mean you don't need to know the column number and the order? Automaticaly? How do you make it? I just want to know it. There are a few ways, the most simple way is to use static data structure (bean) and utils to populate it. I use framework to do this, it can validate all queries before to start application too. But you can use some class for metadata and compare it to resultset metadata retrieved from DB at application startup (it can be generated from DB metadata too).
rs.getString( Metadata.EMAIL_INDEX );
This progamming style works good in practice too.
int index = 1; email = rs.getString( index ++ ); name = rs.getString( index ++ );
It works because you add fields in the most of cases.
|
|
Message #124850
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Pagination
In general, do not write code that relies on the number of result rows from a query because drivers must fetch all rows in a result set to know how many rows the query will return. What is the best way to do pagination (in web pages) without relying on number of rows? You do not relying on number of rows for pagination if you use something like "LIMIT/OFFSET". And you keep the full list in the session or application context and the pagination (and sort order) state in the session context. If you keep the full list in the application context keep in mind that if can be accessed by multiple users.
MC
|
|
Message #124904
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
When will TheServerSide allow post editing ?
Bl..dy typos... >> I relay should be: 'I realy' should be: 'I really' ;-)
|
|
Message #124970
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Pagination
In general, do not write code that relies on the number of result rows from a query because drivers must fetch all rows in a result set to know how many rows the query will return. What is the best way to do pagination (in web pages) without relying on number of rows? You do not relying on number of rows for pagination if you use something like "LIMIT/OFFSET". You can do next/previous buttons using this method, but you wouldn't be able to do a "paging" thing where you've got links for 1-10, 11-20, etc along the bottom without knowing the total number of rows.
I guess what this is trying to say is not do get a recordset and get the number of rows from it to determine how many rows you have, instead do a "select count(foo) ..." as that won't result in the data coming down the pipe.
|
|
Message #125008
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
PreparedStatement to do insert not always the best technique
On Oracle, using PreparedStatement like in the following example might not be performant if the table in which you insert has a lot of columns (whatever you use addBatch or not)
PreparedStatement ps = conn.prepareStatement( "INSERT into employees values (?, ?, ?)");
for (n = 0; n < 100; n++) {
ps.setString(name[n]); ps.setLong(id[n]); ps.setInt(salary[n]); ps.addBatch(); } ps.executeBatch();
Indeed, we experienced performance degrade using this technique on tables with 50 or more colums (in our case, these tables were storing banking products, so it was normal that we had so many business columns in one table). The time spent in all the set... method calls was the bottleneck.
It was more performant to use Statement and litteral values in combination with addBatch when inserting in these tables.
|
|
Message #125056
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Retrieving Auto-Generated Keys
Maybe I'm a bid simple minded, but I don't see why anyone would create tables without primary keys. If that's really the case, I'm sure you have other problems than performance.
Further, the solution explained in the article only works (in my opinion) if you implement the DB access directly using JDBC. Using, for example, CMP Entity Beans, this approach does not work, since you have no real control over the statement used to create the dataset. I wonder if that's also true for O/R mapping tools (TopLink, Cocobase, Hibernate, etc). Does anyone have experience with that?
Regards, Dirk
|
|
Message #125122
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Bummed about PreparedStatements
Maybe parameterized queries have a lot of overhead to compile, but composing queries with all that quote junk is awful. Trying to compose a given vendor's proper date query format is irritating enough alone; a simple call to setDate() (or better yet, setObject()) is so much easier and totally cross-platform. And there's issues with decimals, etc., etc....
Furthermore, composing sql "by hand" (at least theoretically) opens you up to attacks like somebody inserting raw sql into a user interface query field and fooling your code into adding it to the end of a query.
It seems like JDBC should provide a single-execution-optimized PreparedStatement that can take advantage of all the benefits of PreparedStatement.setObject() without the overhead issues.
Then again, I wonder if JDBC drivers/databases can gain any performance benefit when the same query is passed many times to Connection.prepareStatement() when using a JDBC 3.x connection pool? It isn't really feasible to hang onto statements & connections between http requests in a server-side app like I am building.
Either way, my stuff is fast enough that I doubt I'll stop using PreparedStatement. I'd sooner upgrade all the CPU's and buy a new network hub.
|
|
 |
New content on TheServerSide.comNew content on TheServerSide.comNew content on TheServerSide.com |
 |
 |
Reza Rahman explores the features of the proposed JSR 299, Contexts and Dependency Injection for Java EE (CDI). When approved, it promises to be a key feature of Java EE 6.
(November 2, Article)
SAML is an XML-based standard for exchanging authentication and authorization data between security domains. The single most important problem that SAML was created to solve is the Web browser Single Sign-On problem. Many organizations are debating whether to stay with version 1.1 or move to 2.0. This article makes observations about both options.
(September 28, Article)
Joe Ottinger takes a look at how people learn, and applies it to the practice of programming. He notes that understanding how people learn is an essential part of working in a programming team.
(September 22, Article)
Stephen Maryka gave us an article about the Asynchronous Web and posed a number of questions that get examined like an approach to delivering Asynchronous Web capabilities through extensions to existing Java EE technologies.
(July 14, Article)
JavaServer Faces Flex goal is to provide users capability in creating standard Flex components, part of flexSDK which is open sourced through MPL license, as normal JSF components. This article by Ji Hoon Kim will provide an overview of creating a simple multilingual JSF page consisting of JSF Flex tags.
(June 29, Article)
In this session Jeff explores the key characteristics of successful SOA projects. He covers some of the patterns, and anti-patterns, tool sets, and strategies that he himself learned the hard way. Last, he provides a strategy and blueprint for achieving a high likelihood of success in your SOA project.
(June 23, Tech Talk)
Ari Zilka, CTO of Terracotta, Inc., talks about the new features in Terracotta 3.1, announced during JavaOne and available now.
(June 15, Tech Talk)
In this Tech Talk, Josh Long explores an integration challenge using Spring Integration and walks through the implementation, employing and expanding on the basic patterns of Enterprise Application Integration to tie together components into a function integration solution, and then demonstrates how Spring Integration helps address the integration requirements.
(June 15, Tech Talk)
In this Tech Talk, David Geary teaches you: The basics of Google Web Toolkit; How to implement Ajax-enabled applications in Java; Internationalization; Hooking into the browser history mechanism; Remote procedure calls.
(June 4, Tech Talk)
Jon Kern discusses the best architecture/technical solutions and ensure that they are repeated by all developers. By tackling the architecture up-front in a serial manner, subsequent parallel development will be much more manageable and predictable.
(May 28, Tech Talk)
This keynote describes the frustrations of modern knowledge workers in their quest to actually get some work done, and solutions for how to guard yourself against all those distractions. Neal Ford talks about environments, coding, acceleration, automation, and avoiding repetition as ways to defeat the misguided attempts to sap your ability to produce good work.
(May 26, Tech Talk)
Gil demonstrates how new, aggressive uses of already abundant compute capacity by common applications offer competitive value for application designers.
(May 21, Tech Talk)
Chris Keene introduces WaveMaker as a new way to automate the ability to generate Hibernate classes in order to more quickly bring OR mapping into an application.
(May 19, Article)
In this session Nati Shalom demonstrates how to take a standard Java EE web application and scale it out or down dynamically without changes to the application code. Seeing as most web applications are over-provisioned to meet infrequent peak loads, this is a dramatic change because it enables growing your application as needed, when needed, without paying for unutilized resources.
(May 19, Tech Talk)
Download the entire book of Jakarta-Struts Live and learn about Struts MVC, Tiles, the Validator, DynaActionForms, plug-ins, internationalization, and more.
(Book PDF Download)
The Application Server Matrix is a detailed listing of J2EE vendors and their application server products, with information on latest version numbers, J2EE spec support and licensing, pricing, platform support, and links to product downloads and reviews.
(Application Server Comparison Matrix)
|
|