-
starting in JDBC
Hello,
I know already a bit of J2SE but I'd like to start programming with JDBC. The problem is, I don't have a PC myself, I use those at the university lab, so I have some restrictions installing stuff. I've started reading Sun's JDBC tutorial but they just say "will need a DBMS, ask your admin to install and configure it", but hey, no admin for this, so I need to know... can I do it without installing those **** InstallShield stuff which try to write in the windows registry? Do I need to configure a DB server? Can I do it like with MySQL? Where can I find that information? Yeah, I know, "google it", but in fact sometimes it's so much faster and easier if someone can help just a bit, so well I'm trying...
-
you can use a MySQL database, but you still need the jdbc driver installed. (you can get it from mysql.com) If you plan on using a database from another webserver, chances are you won't be allowed to connect. Most are setup to only be accessed through the localhost, such as the scripts run from that particular server.
-
I've downloaded Connector-J from MySQL's site and also installed XAMPP. The MySQL server was working (I could access it from the phpMyAdmin page), but I couldn't find the correct string for gettting a connection (though the tutorial said it should begin with "jdbc dbc:") :
Code:
String url = "jdbc:odbc:connector-j";
Connection con = DriverManager.getConnection(url, user, pass);
what should I write in url? localhost? connector-j? mysql?
Also, I've uncompressed Connector-J but couldn't get the jar file running (no manifest something problem)...
Last edited by dhakir; 12-03-2005 at 09:21 AM.
-
Here's how I connect to mine, where the sql server is on another machine on my network. It then stores the name of all the databases found into a vector. If you don't specify a database at connection time (like i have), you need that last "/" at the end of the address or you'll get a "driver cannot be found" error.
Code:
Vector databases = new Vector();
String host = "192.168.0.1/";
String user = "foo";
String pass = "bar";
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://"+host;
connection = DriverManager.getConnection(url, user, pass);
DatabaseMetaData dbmd = connection.getMetaData();
ResultSet result = dbmd.getCatalogs();
ResultSet result = dbmd.getCatalogs();
while(result.next())
{
databases.add(result.getString(1));
}
}
catch(Exception e)
{}
You shouldn't run the driver jar file, just put it in the "ext" directory of where the jsdk is installed.
-
Thanks, I think I've managed to do something by setting the classpath. In fact, I cannot change the ext folder because I don't have permission.
But is there a way to do it without using Connector/J? Like using some standard generic driver (maybe something related to ODBC)?
-
I cannot change the ext folder because I don't have permission.
I ran into that problem the other day when installing the driver on my mac. had to log in as root.
There's not native driver included with jsdk that I'm aware of.
Similar Threads
-
By manoj nahar in forum Database
Replies: 0
Last Post: 03-07-2002, 01:11 AM
-
By frest in forum oracle.general
Replies: 0
Last Post: 05-01-2001, 07:33 AM
-
Replies: 5
Last Post: 04-18-2001, 03:59 PM
-
By Fabio Luis De Paoli in forum Java
Replies: 2
Last Post: 01-15-2001, 02:33 PM
-
Replies: 3
Last Post: 09-28-2000, 05:22 AM
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
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|