我正在尝试在Java 6中执行sql查询:
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()); } } }我已经在Mac Os X上安装了mysql 5.5集群,在URL中,我刚刚编写了本地IP(本地主机),数据库名称为test. 为什么找不到数据库?我必须安装一些驱动程序吗?我已经安装了数据库,"utente"是一个现有表.
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.
推荐答案我怀疑问题是您的JDBC URL:
I suspect the problem is your JDBC URL:
"jdbc:msql://..."你的意思是
"jdbc:mysql://..."有没有机会?
(是的,您也还需要 MySQL驱动程序在您的类路径中.安装不需要它,但是jar文件将需要可用.)
(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.)
更多推荐
找不到合适的驱动程序
发布评论