Click here to Skip to main content
15,883,938 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hey all, All i would like is assistance to connecting to a database with the .odb file extension

Java
//Put this at the beginning  of your program 	
private static final String DATABASE_FILE_NAME = "OfMiceAndMen.mdb"; // this is the usual dbcon system.
private static final String DRIVER = "jdbc:odbc:DRIVER=" + "{Microsoft Access Driver (*.mdb)};" + "DBQ=" + new File (DATABASE_FILE_NAME).getAbsolutePath () + ";";


	static
	{
		try
		{
			Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
		}
		catch (ClassNotFoundException e)
		{
			System.out.println ("Class not found");
			e.printStackTrace ();
		}
	}

	private Connection dbcon 
//put this in the method where you are running your query
dbcon = DriverManager.getConnection (DRIVER);
Statement stmt = dbcon.createStatement ();
String sql = "SELECT Cue, lights, sound, projection, stagedir, ID FROM Cues WHERE ID = " + I + " "; //4
ResultSet rs = stmt.executeQuery (sql);

while (rs.next ())
{
String c = rs.getString ("Cue");// Cue is the name of the column being queried
c = c + "";
}        



This is the code a friend gave.. Pls help
Posted

1 solution

 
Share this answer
 
Comments
Umar2 8-Oct-12 12:56pm    
It still doesn't work, the "JDBCDriver cannot be resolved to a type".. Thats what it said in Eclipse
Thomas Daniels 8-Oct-12 13:03pm    
Try it with jdbcDriver instead of JDBCDriver.
Umar2 8-Oct-12 14:28pm    
Same result, the "import org.hsqldb.jdbcDriver;" cannot be resolved.. Thats what eclipse returned

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900