Win a copy of Terraform in Action this week in the Cloud forum!

Robert Brunner

Ranch Hand
+ Follow
since Jul 18, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Robert Brunner

Wow, your message totally screwed up my browser window. Very impressive.
Since I can't really see what you posted, I will only be able to give generalities. If you want to set a variable from a ResultSet object, you do is just as you would in any Java application with JDBC. For example, to set an integer value i
<%i = rs.getInt(1) ; %>

Cheers,
Robert
[This message has been edited by Robert Brunner (edited August 16, 2001).]
[This message has been edited by Robert Brunner (edited August 16, 2001).]

Originally posted by Guillaume Compagnon:
What is your opinion on the new release of JDBC API 3.0 ?

A good start point to know about JDBC 3.0 is: http://www-106.ibm.com/developerworks/java/library/j-jdbcnew/
for my part, the RETURN_GENERATED_KEYS function has been waited for a long time
The other features are aimed to improve performance with applications talking with DB. (connection & prepared statement pooling). That is SO important because the bottleneck is always (almost) with the communication with DB.


I am looking forward to the savepoints! Of course getting drivers that implement JDBC 3.0 will be an entirely different story. I know inet has Merlia, but other than that, its slim pickings.

Originally posted by Thomas Kyte:
Well, I would tend to disagree with the Object database comment as a "pointer" as you call it is really a step backwards somewhat in data integrity (we had that with network databases way back when). You lose the referential integrity rule the user wants. You can "point" to a user or a group but there is nothing stopping the system from deleting that user or group (leaving you with a dangling pointer that points to nothing). We can do that with REFs and UDTs as you point out but you have that nasty dangling ref issue.
In a pure relational world (as would be true in an OO world), the data model would involve some super type (suppose we call it "ENTITY"). The USER table would be a child table of ENTITY as would the GROUP table. Now the MESSAGE_TABLE has a foreign key to ENTITY (as the OO model would have a pointer to an ENTITY instance but the pointer might be the USER or GROUP as ENTITY is probably an abstract class)..
So, one method to solve this is to have tables such as:
create table entity( id int primary key, data varchar2(10) );
create table users
( id primary key references entity, other_data varchar2(10) );
create table groups
( id primary key references entity, other_data varchar2(10) );
create table messages
( msg_id int primary key, who_from references entity );


Hi Thomas,
Its all fine to disagree, but be sure your facts are straight. OODBMS often provide referential integrity as a user option. You can propogate behaviors along links however you wish, including locking options, copying behavior (shallow vs. deep), delete behaviors, etc. Thus your criticism is completely unfounded.
The reason OODBMS did not succeed had little to do with the quality of the products, and a lot to do with the strength of the RDBMS vendors and the lack of an OODB standards.
CHeers,
Robert

Originally posted by Jamie Robertson:
If you are using statements you can do the following:
String query = "select * from emp";
System.out.println(query);
rs = stmt.executeQuery(query);
Unfortunately with PreparedStatements you can only print out the individual parts of it:
String query = select * from emp where id = ?";
PreparedStatement ps = con.prepareStatement(query);
System.out.println(query);
System.out.println(value1);
ps.setString(1,value1);
...
Hope this helped a little bit. If you are looking for a method like ResultSet.getQueryString(); I think you're out of luck.

Jamie



Actually, there is a tool called a JDBC spy driver, which actually shows the SQL that is being used by the database (which may be different than what is in your java code. Merant provides a version (not sure who actually wrote it). Basically, the spy driver does the normal stuff, but also logs what it is sending.
Again, very useful for actual debugging, especially with complex joins or stored procedures.
Cheers,
Robert

Originally posted by karim qazi:
Can anyone explain to me how to use the ConnectionPoolDataSource vs. DataSource.
I know how to get a connection using the DataSource interface how can you get a ConnectionPoolDataSource instead?



Easy, rather than creating an object that implements the DataSource interface, you implement an object that implements the ConnectionPoolDataSource.
You then get a PooledConnection object via getPooledConnection(), and then you get a connection from this PooledConnection via getConnection(). Everything else is the same. So essentially, you only have one changed step, and one additional step to take advantage of connection pooling.
<pre>
ConnectionPoolDataSource ds = new ConnectionPoolDataSource() ;
// Set datasource properties
PooledConnection pcon = ds.getPooledConnection() ;
Connection con = pcon.getConnection() ;
<pre>
Could you post more information about the problem you are having?

Originally posted by Robin Richardson:
I've checked all those sites already. They all seem to be geared toward Windows only, of course since I'm not very familiar with Solaris I may be missing something, and I need to know exactly how to add the driver to the Solaris CLASSPATH (/user/....) so that it will work on this system. I have not been able to find the correct settings.
Thank you
Robin


Robin,
Type 4 rivers are pure Java, they will work on any JVM (in theory at least). Try to download an evaluation version and test it out. I now people who have done JDBC on an AS400.
As far as CLASSPATH, it works just like on Windows. Exact format depends on your shell. Try set CLASSPATH for sh, and setenv CLASSPATH for csh. Driver documentation should help.

Originally posted by Raghav Subramanian:
Hi,
I am trying to insert multiple values into multiple tables at a single instance.I have a HTML form and Servelt that connects me to the MSAccess database . i have 4 different tables in the database.and i want to enter the values in the form to these tables in a single submit button click. i tried doing
Statement st = conn.createStatement();
st.addBatch("insert into table 1");
st.addBatch("insert into table 2");
st.addBatch("insert into table 3");
st.addBatch("insert into table 4");
int [] count = st.executeBatch();
but i am getting a error all the time i do it this way , is this any other way to carry out this type of operation.
thanks
raghav


Raghav, What error are you getting? You could do this without a batch statement. Disable autocommit, do all the inserts, and then do an explicit commit. You may need to do this if your driver does not support batch statements (which I do not think the JDBC-ODBC bridge does).
Robert

Originally posted by justin deming:
Hi,
I want to check if the resultset from my jdbc/oracle query contains anything so I say:
if(resultSet.next() == false) {
tell the user there were no results using jsp1
}
else {
while(resultSet.next()) {
print the results using jsp2
}
The problem occurs when the resultSet is not empty and else is executed. Since resultSet.next() has been called in the if statement the results start printing at the second record. I tried calling resultSet.previous() before the while loop but it is a forward only resultSet.
Can anyone think of a better way to check this condition or how the make the resultSet traverseable in two directions?


Hi Justin,
First, the answer to your second question is that in JDBC 2, ResultSets can be bi-directional, so you can start at the bottom and work your way up or vica-versa. You can also setFetchDirection to tell the database you want to do this implicitly. Of course all of this assumes your driver and database support these sorts of things.
Now, on to your first question. There are several options you have. First, you can do the normal thing
while(rs.next() {
// do your thing
status = true ;
}
if(!status){
// Tell user no data
}
You also could do something similar to what you had written (and was sort-of indicated by an earlier post.
if(rs.next()){
do {
//process the results
}while(rs.next())
}else{
// tell user no data
}
Hope this helps.
Cheers,
Robert
20 years ago
Try doing it in JSP. You can set up a loop to itereate over the result set and print out the html as you want.
20 years ago

Originally posted by Sophia Oscario:
I try to use Pool Manager 2.0 to handle database connection to MySQL from JSP.
But it returns an execption :
Exception Report:
javax.servlet.ServletException: javax/sql/ConnectionEventListener
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:442)
at org.apache.jsp.JDBCtest_jsp._jspService(JDBCtest_jsp.java:123)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:200)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:379)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:453)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:254)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:194)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:255)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:225)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2252)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:446)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:875)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:952)
at java.lang.Thread.run(Thread.java:484)

Here's My code :
<html>
<head>
<title>JDBC - MySQL</title>
</head>
<%@ page language="java" import="java.sql.*,com.codestudio.util.*" %>
<body>

<% SQLManager myManager = SQLManager.getInstance(); Connection myConn = myManager.requestConnection(); Statement st = myConn.createStatement(); ResultSet rs = st.executeQuery("select * from employee"); if (rs != null) { while (rs.next()) { String eid = rs.getString("empid"); String name = rs.getString("lastname") + ", " + rs.getString("firstname"); String extention = rs.getString("extention"); %> <% } } st.close(); myManager.returnConnection(myConn); %>
ID Name Extention
<%=eid %> <%=name %> <%=extention %>


</body>
</html>
Please anybody can tell me what's wrong ...
Thanks



I can't see you code. Try to resubmit just your code.

Originally posted by JiaPei Jen:
Is the class12.zip bundled with the Oracle8i? Where should I place the class12.zip in my directory?


Yes, it is included, look under your Oracle Home directory in the JDBC/lib subdirectory. Once you find it, you will need to put it in the classpath of any JVM that you want to be able to access it.
Cheers,
Robert

Originally posted by Farooq Ali:
Another question..
Can MS Ole-Db be used somehow instead of the standard ODBC/DSN technique?? to connect to a java program??
FArooq


Hi Farooq,
I have never heard/seen it done, although maybe some of the type 4 JDBC drivers do that directly. Java programs expect to talk to a database using the JDBC API (even JDO is layered on top of JDBC for SQL data stores). The only way ODBC is used is with the JDBC-ODBC bridge.
Cheers,
Robert

Originally posted by Robin Richardson:
Hello, I'm working on a project that requires that the program I'm working on runs on a Solaris 7 server. I have written the program on Windows 2000 due to problems getting a driver for AS400 (DB2, or so I'm told) to work on the Solaris 7 box. Can anyone tell me if there is a driver available? If so, please direct me to that site, and the appropriate download/installation instructions
Thank you
Robin Richardson


Robin, did you try IBM's site? Also, check out drivers from Merant, and HITSW.
http://industry.java.sun.com/products/jdbc/drivers/search-results/1,2722,,00.html

Originally posted by Chetan,Mehta:
Hi,
Can someone please tell me what are the differences between avaliable types?
How do we identify for a given scenario which is the best suitable driver for use?
I understand that we have type1, type2 , type3 and type4 driver avaliable by Specification.
I needed help understanding scenario where particular driver can be the best fit.
Thanks,
Chetan



Hi Chetan,
This is actually easy, although it may not seem so. Type 1 is the JDBC-ODBC bridge driver. You only use it for ODBC connections, like ACCESS or Excel. It is not for distributed Apps.
Type 2 is basically non-existant, don't even worry about them (they are part Java, part native code, thus DB specific code has to be installed on each client).
Type 3 drivers communicate in a database independant protocol with a special middleware server, which then communicates directly with your database. This type is nice if you want to be able to easily move your app between databases (but this is less important with introduction of datasources).
Type 4 is a high performance all Java driver which communicates direcxtly with the database of choice.
I would recommend you get a Type 4 if at all possible.
Cheers,
Robert