hi all .. java/jdbc newbie here ... i cant seem to perform the most basic step for database connectivity using java . here is my code :
[CODE=java]
import java.sql.*;
public class connect
{
public static void main (String[] args)
{
Connection conn = null;
try
{
String userName = "myname";
String password = "mypassword ";
String url = "jdbc:mysql:loc alhost";
Class.forName ("com.mysql.jdb c.Driver").newI nstance ();
conn = DriverManager.g etConnection (url, userName, password);
System.out.prin tln ("Database connection established");
}
catch (Exception e)
{
System.err.prin tln ("Cannot connect to database server");
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.prin tln ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
}
[/CODE]
when i am connecting to the same server using some other programming language such as python it is working perfectly fine .
what i cant figure out is what to assign to the "url" variable.. in other words .. how shall i determine the url of the company mysql server ? every time i run this code i get the same error "Cannot connect to database server".
I am using debian linux OS
any help appreciated,
regards
rhitam.
[CODE=java]
import java.sql.*;
public class connect
{
public static void main (String[] args)
{
Connection conn = null;
try
{
String userName = "myname";
String password = "mypassword ";
String url = "jdbc:mysql:loc alhost";
Class.forName ("com.mysql.jdb c.Driver").newI nstance ();
conn = DriverManager.g etConnection (url, userName, password);
System.out.prin tln ("Database connection established");
}
catch (Exception e)
{
System.err.prin tln ("Cannot connect to database server");
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.prin tln ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
}
[/CODE]
when i am connecting to the same server using some other programming language such as python it is working perfectly fine .
what i cant figure out is what to assign to the "url" variable.. in other words .. how shall i determine the url of the company mysql server ? every time i run this code i get the same error "Cannot connect to database server".
I am using debian linux OS
any help appreciated,
regards
rhitam.
Comment