Java +sql

Hi, I’m working on the project in JAVA and I’ve got a problem with connection to database. My Database (in sql) is located on This is a fragment of my java’s code:

String url = “”;//mysql is a name of my database
String username = “projektanty”;
String password = “******”;

Statement s = null;
Connection c = null;

	try {

		} catch (Exception e) {
			System.err.println("Error loading JDBC/ODBC.");
		try {
			c = DriverManager.getConnection (url, username, password);//the problem is with URL, I think...
			s = c.createStatement();
			} catch (Exception e) {
				System.err.println("cannot connect to "+url);

Where’s the problem? Help me, plz.

Try to use ‘localhost’ instead of ‘url’ and make sure that your database-name [quote]String url = “”;//mysql is a name of my database[/quote] is the same like your username. Your database can’t be named “mysql” - it is “projektanty” or even start with projektanty.

[quote]Try to use ‘localhost’ instead of ‘url’ [/quote]What do You mean?

My database’s name is of course “projektanty”, soryy for mistake. So now my url is:
url = “”;

But it doesn’t still work:/

url, username, password

password=your pw

But my applet isn’t located on How would my program know that localhost = ?

You can’t connect your database to external scripts, those functions are disabled to prevent abuse…

I’m writing my program in eclipse sdk. what files should I put on Where should I put them ? (in what directory?)

Sry, I can’t help you with those programs.

Ok, but if I use WAMP (and now my url = localhost)… do I have to configure anything ? I mean Data Sources (ODBC) in Control Panel or anything else ?

I’m not sure - I only know SQL, php, css, html and some cms’ - but nothing about ODBC or other databse-Systems

thanks for help.

If you use a ODBC-Connection, you can create the Database directly in Windows. But I really don’t know, what to do in JDBC…

Google said:

[quote]Google said:[/quote]Yeah, I know… but I’ve got a problem… how tu use it?

The documentation can be found here: :astonished:

when I changed part of my code :
try {
c = DriverManager.getConnection (url, username, password);
s = c.createStatement();
} catch (Exception e) {
System.err.println(“There’s a problem with connection to " + url+”\n"+e);// there’s a change (+e)

There’s a problem with connection to jdbc:odbc://localhost/byczabaza
java.sql.SQLException: [Microsoft][Driver Manager ODBC] Cannot find a name of data source and there’s no default driver.

It can mean that I should configure something in Control Panel… but how to ?

you want to use Microsoft ODBC-Database?
It’s very similar to the control panel in XP. You don’t need to use XAMPP and MySQL then :wink:

If you want to use MySQL, you need something like this:

try {
  c = DriverManager.getConnection ("jdbc:mysql://localhost/byczabaza?user=USER&password=PASSWORD");
  s = c.createStatement();
} catch (Exception e) {
    System.out.println("SQLException: " + ex.getMessage());
    System.out.println("SQLState: " + ex.getSQLState());
    System.out.println("VendorError: " + ex.getErrorCode());

moreover you will need to load the JDBC-Objects, like

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

i think you know, how to add Objects to your Java-Projects. I haven’t done anything with Java before :wink: