I am trying to execute a sql query in java 6:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
/**
*
* @author ramy
*/
public class JavaTest
{
public static void main(String[] args)
{
try
{
String url="jdbc:msql://127.0.0.1:1521;DatabaseName=test";
Connection ct=DriverManager.getConnection(url,"","");
Statement st=ct.createStatement();
ResultSet result;
result=st.executeQuery("select * from utente");
while(result.next())
{
String temp=result.getString("Num_tessera");
System.out.println(temp);
}
ct.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
I have installed mysql 5.5 cluster on Mac Os X, in the url I have just written my local IP (localhost), and the database name is test.
Why doesn’t it find the database? Do I have to install some driver? I already have the database installed and “utente” is an existing table.
I suspect the problem is your JDBC URL:
Did you mean
by any chance?
(And yes, you’ll also need the MySQL driver in your classpath. It’s not something you need to install, but the jar file will need to be available.)