-
Java/JDBC Help
Hi:
As a JAVA beginner, I just download J2SDK1.4.2 and NetBeans IDE 3.6. for Windows.
I have some questions on JDBC driver and SQL function:
1) How to find a Driver Name for Access 2000 or MS SQL except JDBC-ODBC Bridge (I have Access 2000 and SQL on my PC) for Class.forName(). --(.Jar files only?)
2) Can I directly code Driver and its attributes for Data Source in URL instead of DSN? And how to code them?
3) How to drop a table from a database, for example to drop a table in a MS SQL file. I can't find sample code for table drop neither in NetBeans nor JAVA (only found updating and querying).
Appreciate your help!
-
1.
For Access - You will need to use the Bridge.
For SQL server - go here http://jtds.sourceforge.net/ - They have a driver and directions.
You might want to pickup Squirrel too. - squirrel-sql.sourceforge.net
2. http://www.devdaily.com/java/edu/pj/pj010024/
3. Do exactly like you would for an update query but use "Drop Table tablex" replacing tablex with your table name. As long as your user as the authority it will work. Check SQL Server Books Online in case the syntax is not correct. I think it is.
-
Thanks for helping me on #1 and #3.
A question on #2 for Interbase (following sample code):
// Establish a connection to an Interbase database using JDBC.
import java.sql.*;
class JdbcTest1 {
public static void main (String[] args) {
try {
// Step 1: Load the JDBC driver.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Step 2: Establish the connection to the database.
String url = "jdbc dbc:contact_mgr";
Connection conn = DriverManager.getConnection(url,"user1","password");
} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}
In String url = "jdbc dbc:contact_mgr" -- Here "contact_mgr" is a database name.
Why it did not put a full path to a database (If there are multi files with same name, such as Access in different subdirs, how URL to distinguished them)? Do I need to do some things before? Such as building a connection with Runtime ->Databases -> Driver -> Connection?
I want to pass RUL parameters on a fly accurately.
-
You will need to have different DSN's for each "database".
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks