Reputation: 22006
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.
Upvotes: 0
Views: 408
Reputation: 8881
also please check the port in your URL , as 1521 is Oracle and MySQL is 3306
Upvotes: 1
Reputation: 1503829
I suspect the problem is your JDBC URL:
"jdbc:msql://..."
Did you mean
"jdbc:mysql://..."
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.)
Upvotes: 5