Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Database

  Asked By: Ricky    Date: Dec 12    Category: Java    Views: 453
  

I'm still having trouble accessing a database from java. I added the
correct file to all the dsn i could find in the odbc window under
control panel. Anyone know what i could be doing wrong? Hers is my
code and throws an error on line 12 where i use getConnection:

Plz help cause this is very important in an project i'm working on.

import java.sql.*;

public class Lookup
{
public static void main (String [] args)
{
String dbUrl = "jdbc:odbc:StelliesXP-2003-05-21.mdb";
try
{
Class.forName (
"sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection (
dbUrl, " ", " ");
Statement s = c.createStatement ();
ResultSet r =
s.executeQuery (
"SELECT FIRST, LAST, EMAIL " +
"FROM StelliesXP-2003-05-21.mdb persone " +
"WHERE " +
"(LAST='" + args [0] + "') "
);
while (r.next ())
{
System.out.println (
r.getString ("Last") + ", "
+ r.getString ("First")
+ ": " + r.getString ("EMAIL"));
}
s.close ();
}
catch (Exception e)
{
e.printStackTrace ();
}
}
}

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Haru Tanaka     Answered On: Dec 12

String dbUrl = "jdbc:odbc:StelliesXP-2003-05-21.mdb";

try specifying the path to the database.

 
Didn't find what you were looking for? Find more on Database Or get search suggestion and latest updates.




Tagged: