Click to See Complete Forum and Search --> : n00b help with jdbc:odbc connection???
sparq
04-08-2005, 09:39 AM
I could really use some help folks, im messing with Java to try and query a MySQL database. I went into BEA and copied a current connection pool, but changed it to the new server/database info but I dont get any results.
CONNECTION POOL
URL: jdbc:weblogic:mssqlserver4:limo@@10.1.1.15:1433
DRIVER CLASS NAME: weblogic.jdbc.mssqlserver4.Driver
PROPERTIES: user=limo
password=limo
server=limo@10.1.1.15:1433
JAVA PAGE
<%@ import="java.sql.*" %>
<% Class.forName("weblogic.jdbc.mssqlserver4.Driver"); %>
<html>
<head>
<title>Fetching Data From a Database</title>
</head>
<body>
<%
Connection connection = DriverManager.getConnection(
"jdbc:weblogic:mssqlserver4:limo", "limo", "limo");
Statement statement = connection.createStatement();
ResultSet resultset =
statement.executeQuery("select * from Vehicles");
%>
<table border="1">
<Tr><td>Limo ID</td><td>Limo Color</td><td>Passengers</td><td>Is Active</td><td>Short Description</td><td>Long Description</td></tr>
<% while(resultset.next()){%>
<tr><Td><%= resultset.getString(1) %></td>
<Td><%= resultset.getString(2) %></td>
<Td><%= resultset.getString(3) %></td>
<Td><%= resultset.getString(4) %></td>
<Td><%= resultset.getString(5) %></td>
<Td><%= resultset.getString(6) %></td>
</tr>
<% } %>
</table>
</body>
</html>
Anyone give me a hand? I think my connection isnt setup right, but im poking in the dark - im lost, anyone? My database server is "SQLPIX" and the database is "limo" -- any help is much appreciated!!!! :cool:
Khalid Ali
04-08-2005, 09:42 AM
the only thing missing here is that what is the error you are getting?
buntine
04-08-2005, 09:43 AM
Are you receiving an error or just no results at all?
sparq
04-08-2005, 09:44 AM
No error, I just get no results.
I am taking my example right from a Java book, I even tried using a form to select which record, that is the only way I could actually get an error, it would just say it was unable to display the page. But if I did File / Open and opened the page from the web, I would see my basic info (header and such) just no page info. So its not like the page ISNT there, which leads me to think my connection isnt correct???
buntine
04-08-2005, 10:18 AM
May sound like a silly question, but mayby the table is empty. Have you double-checked it?
You may also need to check the log files in webapps/logs directory. Something useful may be in there.
Regards.
sparq
04-08-2005, 10:19 AM
The table isnt empty, I have a cold fusion query pulling the same exact information and it works fine.
sparq
04-08-2005, 10:23 AM
Does anyone know where the mssqlserver4 comes in from?
Like I said, I basically just copied an already existing connection, but there are TWO differant servers in the group, and the connection I copied came from the other "machine" and not the "SQLPIX" machine, so maybe this name is differant? I take it this name is given some place on the server? Where can I go look to pull this up? Maybe????????
*scratching my head*
Khalid Ali
04-08-2005, 10:27 AM
when u run WLS it connects to the DB(if you have set the db conn in the management console), if you have not and trying to connect on the fly then it must give you some info, put the debugging statements after each java line of code and see where it stops.
By the way , using Business logic(db con) in your jsp page is one of the worst practices you can adopt.You should have all of your db connection stuff in a class separate and use that in your jsp page.
sparq
04-08-2005, 10:32 AM
Well like I said, I dont exactly KNOW Java -- im really doing this just to test the connection to make sure things work, which obviously they arent.
debugging?
Khalid Ali
04-08-2005, 10:39 AM
after every line of code except the code in while loop put the following line, just make sure that you change the number to an appropriate number
System.out.println("LINE 1: worked");
System.out.println("LINE 2: worked"); and so on
sparq
04-08-2005, 10:42 AM
When I do a View / Source I shouldnt be seeing all the <% %> tags should I ?????
Mine are showing up...
Khalid Ali
04-08-2005, 10:53 AM
yes the must not show up in view source, this means you are messing up a qoute here and there, i'd say remove this part of the code
<table border="1">
<Tr><td>Limo ID</td><td>Limo Color</td><td>Passengers</td><td>Is Active</td><td>Short Description</td><td>Long Description</td></tr>
<% while(resultset.next()){%>
<tr><Td><%= resultset.getString(1) %></td>
<Td><%= resultset.getString(2) %></td>
<Td><%= resultset.getString(3) %></td>
<Td><%= resultset.getString(4) %></td>
<Td><%= resultset.getString(5) %></td>
<Td><%= resultset.getString(6) %></td>
</tr>
<% } %>
and just try to see if your connection is good first and put debugging statements as I showed you before
sparq
04-08-2005, 10:55 AM
When I preview the code, I see ALL of the page from the top <%@page import="java.sql.*"%>
all the way down...
Maybe my error is in that I am using dreamweaver? One of the file saving options is a *.jsp so I assumed that was ok? Should I be doing this another way?
Khalid Ali
04-08-2005, 11:39 AM
just check to see if the page extension is jsp
buntine
04-08-2005, 12:13 PM
Are you running the page through localhost? And do you have Java and a Web Server set up on your machine?
That is your problem, the page is not being processed.
Regards.
sparq
04-08-2005, 12:46 PM
So I have to setup the JSP through IIS correct?
Ugh, damn "Test" server, I should have just thrown it on the live server hahaha! I will come back and let yall know if I can get in, or what errors im getting.
*doh*
Khalid Ali
04-08-2005, 03:23 PM
good catch buntine,
I could have never imagined ...... not even running a webserver.
for sparq, you will need to setup java servlet/jsp server such as tomcat( a free one form jakarta.apache.org)
IIS is for MS crap,
ray326
04-08-2005, 08:59 PM
DRIVER CLASS NAME: weblogic.jdbc.mssqlserver4.DriverIs that a MySQL driver? Looks like SQL Server to me.