The Artima Developer Community
Sponsored Link

Java Answers Forum
JDBC connection trouble

7 replies on 1 page. Most recent reply: Jan 20, 2005 12:36 PM by lalama fodie toure

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 7 replies on 1 page
lalama fodie toure

Posts: 11
Nickname: lalama11
Registered: Nov, 2004

JDBC connection trouble Posted: Jan 18, 2005 5:57 AM
Reply to this message Reply
Advertisement
here's the code i just' can't find out why it would work

thanks <br><br><br><br><br><br>
import java.sql.*;<br>
import javax.sql.DataSource; <br>
import java.io.*;<br>
import javax.naming.InitialContext;<br>

class Datasource{<br>

public static void main(String[] lalama)throws <br>IOException{<br>

System.out.println(" Enter the database file name ");<br>
String dsn="jdbc:odbc:"+Driverdemo.in.readLine();<br>


try{

System.out.println( "Initializing the naming context");<br>


InitialContext init=new InitialContext();<br>


System.out.println("Looking up "+dsn);<br>

DataSource source=(DataSource)init.lookup(dsn);<br>


System.out.println( " Establishing.. a connection ");<br>

Connection con=source.getConnection();<br>


System.out.println(" Connected to "+con.getCatalog());<br>


}catch(SQLException s){

System.out.println(s+" Just occured ");<br>
}catch(Exception e){
e.printStackTrace();
}<br>
}<br>
}


Chris Miller

Posts: 23
Nickname: lordsauron
Registered: Jan, 2005

Re: JDBC connection trouble Posted: Jan 18, 2005 9:48 PM
Reply to this message Reply
The first error I saw was that you didn't make the class public - I might just be ignorant of what you're trying to do - but most classes are public.

Chris Miller

Posts: 23
Nickname: lordsauron
Registered: Jan, 2005

Re: JDBC connection trouble Posted: Jan 18, 2005 9:51 PM
Reply to this message Reply
On second inspection, when you caught the SQLExcption, I think it needs to be to error stream e. You might be doing something different that I don't know about - specify the errors you're getting from the compiler.

lalama fodie toure

Posts: 11
Nickname: lalama11
Registered: Nov, 2004

Re: JDBC connection trouble Posted: Jan 19, 2005 4:08 AM
Reply to this message Reply
Anyway thanx for you interest on that topic
it's really got little to do with the class being public or private
this cod actually compil fine
i just got a exception on runtime
Jdbc:odbc brigdge not found
or some such
it's trying to access some database

Lynn Hollerman

Posts: 67
Nickname: gmholler
Registered: Mar, 2002

Re: JDBC connection trouble Posted: Jan 19, 2005 2:22 PM
Reply to this message Reply
That's just it - in the code, you don't have any kind of bridge defined for your jdbc driver. Depending on your database, the exact format of your jdbc:odbc:<whatever> line will be different; but don't confuse that with the database name - they're two different things and can't be used interchangably. It seems you're trying to set up a JNDI Context sort of thing - but that doesn't have to be the same thing as what's in your definition of a JDBC driver. I would think the API for getConnection()would show you the difference - one is often used in that, the other in what you do with a Context and your DataSource definition.

Lynn.

lalama fodie toure

Posts: 11
Nickname: lalama11
Registered: Nov, 2004

Re: JDBC connection trouble Posted: Jan 19, 2005 3:56 PM
Reply to this message Reply
Thanx a lot lynn
but what would you suggest if i were to connect to microsoft access database
or excel or whaterever piece of code would be appreciated

Lynn Hollerman

Posts: 67
Nickname: gmholler
Registered: Mar, 2002

Re: JDBC connection trouble Posted: Jan 20, 2005 11:00 AM
Reply to this message Reply
As a matter of fact, it WAS an MS-Access database I had researched how to connect to; I looked in this forum, and found the answer here. The URL/statement I ultimately used for the connection was

jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=<your database>.mdb

This may or may not help you; it depends on how your getConnection() method defines things. If you need more of an example, do a search on this forum for "Access" or the like; I know I found many good examples here!

Lynn.

lalama fodie toure

Posts: 11
Nickname: lalama11
Registered: Nov, 2004

Re: JDBC connection trouble Posted: Jan 20, 2005 12:36 PM
Reply to this message Reply
let thanx you before hand
i'll you know how it is goin
thanx a lot !
best regard

Flat View: This topic has 7 replies on 1 page
Topic: Is there a Visual GUI editor ? Previous Topic   Next Topic Topic: Bluetooth + Java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use