Ajay Chauhan

Greenhorn
+ Follow
since Dec 10, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Ajay Chauhan

Hi! Kevin.....
here is ur step by step procedure to connect to an access DB...
1.) Create a system DSN for ur DataBase(*.mdb file)
to learn how to do this u can go thru this WebSite:
http://www.webwizguide.info/asp/tutorials/setting_up_dsn.asp
2.) In ur java code load the jdbc-odbc bridge driver in the following manner:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
3.) Create a connection using :
String url = "jdbc dbc:Ajay";
Connection con = DriverManager.getConnection(url,"myLogin", "myPassword");
where Ajay is ur system DSN name.and if u don't have any passord or login then ur connection variables wud be like this:
String url = "jdbc dbc:Ajay";
Connection con = DriverManager.getConnection(url,"", "");
4.) Next is creating statement objects and resultset objects......For complete info on this u can read the following tutorial..
http://www.interex.org/pubcontent/enterprise/jan00/14chew.html
5.) u can have look at this sample code :
Hope all this helps u solve ur problem.
Thanks Joe Ess.....
the link you referred to proved really helpful.....
i used the following url for dsn:
String dsn = "jdbc dbc river={Microsoft Access Driver (*.mdb)};DBQ=//localhost/DataBase/test.mdb";
and the code worked fine......but i had to share the database folder.
there is one more thing i want to know.....how can one map a n/w drive???
Thanx to you Mr. Bear Bibeault for informing me about the naming rules.......as requested by you i have changed my name in my profile.......
but i haven't received my solution as yet....pls....help me if you can....it's important.
Hi! all.....
i am facing a problem while executing the following code.The program runs fine if i give DSN variable as....
String dsn = "jdbc dbc:Test";
but when i try to give my DSN variable by attaching my machine ip address to it in the following manner an error results..
String dsn = "jdbc dbc://172.17.211.38:400/Test";
i m connecting to an MS Access database with dsn name as 'Test' configured thru Data Sources(ODBC) in control panel.....and by now u must have understood that i want to connect to my database from a different machine in the LAN....pls. help me.
the error is:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6031)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:2458)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:3
20)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:163)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:177)
at Connect.select(Dbase.java:52)
at Dbase.main(Dbase.java:15)
the code is:
import java.sql.*;
import java.util.*;
import sun.jdbc.odbc.*;
class Dbase
{
public static void main(String[] args)
{
Connect inst_Connect = new Connect();
inst_Connect.Ajay();
try
{
inst_Connect.select();
}
catch (Exception ee1)
{
ee1.printStackTrace();
}
}
}
class Connect
{
void Ajay()
{
// Load the JDBC-ODBC bridge driver
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch( ClassNotFoundException ee)
{
ee.printStackTrace();
}
}
void select() throws SQLException
{
try
{
// ODBC data source name
Connection con;
System.out.println("1 \n");
String dsn = "jdbc dbc://172.17.211.38:400/Test";
//String dsn = "jdbc dbc:Test";
String user = "";
String password = "";
// Connect to the database
con = DriverManager.getConnection(dsn, user, password);
System.out.println("2 \n");
// Shut off autocommit
con.setAutoCommit(false);
Statement stmt; // SQL statement object
String query; // SQL select string
ResultSet rs; // SQL query results
boolean more; // "more rows found" switch
String v2; // Temporary storage results
Vector results = new Vector( 10 );
query = "SELECT FirstName, LastName " + "FROM StudentInfo ";
stmt = con.createStatement();
rs = stmt.executeQuery(query);
// Check to see if any rows were read
more = rs.next();
if (!more)
{
System.out.println("No rows found.");
return;
}
// Loop through the rows retrieved from the query
while (more)
{
v2 = "Name: " + rs.getString("FirstName") + " " + rs.getString("LastName");
System.out.println( v2 );
results.addElement( v2 + "\n" );
more = rs.next();
}
rs.close();
stmt.close();
}
catch( Exception ee)
{
ee.printStackTrace();
}
}
};
Hi! all.....
i am facing a problem while executing the following code.The program runs fine if i give DSN variable as....
String dsn = "jdbc dbc:Test";
but when i try to give my DSN variable by attaching my machine ip address to it in the following manner an error results..
String dsn = "jdbc dbc://172.17.211.38:400/Test";
i m connecting to an MS Access database with dsn name as 'Test' configured thru Data Sources(ODBC) in control panel.....and by now u must have understood that i want to connect to my database from a different machine in the LAN....pls. help me.
the error is:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6031)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:2458)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:3
20)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:163)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:177)
at Connect.select(Dbase.java:52)
at Dbase.main(Dbase.java:15)
the code is:
import java.sql.*;
import java.util.*;
import sun.jdbc.odbc.*;
class Dbase
{
public static void main(String[] args)
{
Connect inst_Connect = new Connect();
inst_Connect.Ajay();
try
{
inst_Connect.select();
}
catch (Exception ee1)
{
ee1.printStackTrace();
}
}
}
class Connect
{
void Ajay()
{
// Load the JDBC-ODBC bridge driver
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch( ClassNotFoundException ee)
{
ee.printStackTrace();
}
}
void select() throws SQLException
{
try
{
// ODBC data source name
Connection con;
System.out.println("1 \n");
String dsn = "jdbc dbc://172.17.211.38:400/Test";
//String dsn = "jdbc dbc:Test";
String user = "";
String password = "";
// Connect to the database
con = DriverManager.getConnection(dsn, user, password);
System.out.println("2 \n");
// Shut off autocommit
con.setAutoCommit(false);
Statement stmt; // SQL statement object
String query; // SQL select string
ResultSet rs; // SQL query results
boolean more; // "more rows found" switch
String v2; // Temporary storage results
Vector results = new Vector( 10 );
query = "SELECT FirstName, LastName " + "FROM StudentInfo ";
stmt = con.createStatement();
rs = stmt.executeQuery(query);
// Check to see if any rows were read
more = rs.next();
if (!more)
{
System.out.println("No rows found.");
return;
}
// Loop through the rows retrieved from the query
while (more)
{
v2 = "Name: " + rs.getString("FirstName") + " " + rs.getString("LastName");
System.out.println( v2 );
results.addElement( v2 + "\n" );
more = rs.next();
}
rs.close();
stmt.close();
}
catch( Exception ee)
{
ee.printStackTrace();
}
}
};