Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connecting to database for beginner 1

Status
Not open for further replies.

oaklandar

Technical User
Feb 12, 2004
246
US
I am trying to create my first database connection on my local Tomcat server on a Windows workstation. I have a local Access 2000 database on this workstation that I want to start with. The below gives me a bunch of error messages and also I dont see where I can declare the datasource name?

Please advise what I need to modify or do to get this to work??

Code:
<%@ page import="java.sql.*" %>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); %>

<html>
<head>
	<title>Untitled</title>
</head>

<body>
<% Connection connection = DriverManager.getConnection("jdbc:odbc:data", "", "");
Statement statement = connection.createStatement();
ResultSet resultset= statement.executeQuery("select * from mytable"); %>

<br>
<% while(resultset.next())
   { %>
         Data output:
         <%= resultset.getString(1) %>
<% } %>
</body>
</html>
 
Your DS name in this line :
DriverManager.getConnection("jdbc:eek:dbc:data", "", "");

is "data".

It is usually helpful if you post the error messages - they may mean nothing to you, but may to us !

Have you declared your Access DB as a datasource in the ODBC manager ?



--------------------------------------------------
Free Database Connection Pooling Software
 
Another question about the OOP syntax.
For the below Object Oriented statements:

Code:
<% Connection connection = DriverManager.getConnection("jdbc:odbc:data", "", "");
Statement statement = connection.createStatement();
ResultSet resultset= statement.executeQuery("select * from mytable"); %>


Connection is the class name and connection is the creation of a new object?
DriverManager is another class with getConnection as a method
where getConnection has 3 arguments? This is all part of the sql class library?

Please clarify this so I can understand the OOP syntax and meaning.
 
I'm not sure how "OOP" it is ... but yes,

Connection, DriverManager, Statement and ResultSet are all part of the core SQL API packaged into "java.sql".

connection is an instantiated object of the Connection class, which is returned by the static method getConnection() which is part of the class DriverManager.

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top