What do you mean with "jdbc programs" ?
Eclipse has a built-in database explorer, see Window - Show View - Data - Database Explorer. There you can specify connection and driver and then explore the database. Maybe you mean this?
If you just want to know how to write Java code which makes use of the JDBC API, then refer to the JDBC tutorial which is available at Sun.com and usually also at the websites of the database manfacturers which provides JDBC drivers. For example, http://java.sun.com/docs/books/tutorial/jdbc/ (JDBC tutorial) and http://www.mysql.com/products/connector/j/ (MySQL JDBC drivers and lots of documentation).
thanks for the reply. i did'nt knew eclipse had a builtin JDbc driver. anyways i was trying to run my program and it says something about classpath. i have not download any jdbc driver or anyhthing.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
/**
A simple data source for getting database connections.
*/
public class SimpleDataSource
{
/**
Initializes the data source.
@param fileName the name of the property file that
contains the database driver, URL, username, and password
*/
public static void init(String fileName)
throws IOException, ClassNotFoundException
{
Properties props = new Properties();
FileInputStream in = new FileInputStream(fileName);
props.load(in);
String driver = props.getProperty("jdbc.driver");
url = props.getProperty("jdbc.url");
username = props.getProperty("jdbc.username");
password = props.getProperty("jdbc.password");
Class.forName(driver);
}
/**
Gets a connection to the database.
@return the database connection
*/
public static Connection getConnection() throws SQLException
{
return DriverManager.getConnection(url, username, password);
}
private static String url;
private static String username;
private static String password;
}
Main
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
/**
Tests a database installation by creating and querying
a sample table. Call this program as
java -classpath driver_class_path;. TestDB database.properties
*/
public class TestDB
{
public static void main(String[] args) throws Exception
{
if (args.length == 0)
{
System.out.println(
"Usage: java -classpath driver_class_path;."
+ " TestDB database.properties");
return;
}
else
SimpleDataSource.init(args[0]);
Connection conn = SimpleDataSource.getConnection();
try
{
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE Test (Name CHAR(20))");
stat.execute("INSERT INTO Test VALUES ('Romeo')");
ResultSet result = stat.executeQuery("SELECT * FROM Test");
result.next();
System.out.println(result.getString("Name"));
stat.execute("DROP TABLE Test");
}
finally
{
conn.close();
}
}
}
I was not talking about a built-in JDBC driver, but about a Database Explorer.
Well, it appears that you just don't understand how to communicate with databases in Java. Check the links I gave you above afterwards. It points to a JDBC tutorial. You just need to download the JDBC driver from the website of the database manfacturer (mysql.com for MySQL, microsoft.com for MSSQL or Access, oracle.com for Oracle, ibm.com for DB2, etc) and put it in the classpath (build path) of the Eclipse project.
Oh, don't forget to install an actual database, if you haven't done it yet.