我开发了一个程序,在该程序中,我使用JDBC进行一些数据库连接并发送一些查询。
我使用了MySQL,NetBeans 6.9在Ubuntu 11.04下作为平台。当我从NetBeans运行应用程序时,它运行得很好,但当我尝试从终端运行它时,我会得到SQL异常。这是产生SQL异常的函数。程序在"建立即结束"行之前终止。
public Connection Establish(String iname, String ipassword) throws SQLException
{
System.out.println("Establish...");
if(conn == null)
{
conn = DriverManager.getConnection("jdbc:mysql://localhost/ANU",
iname, ipassword);
}
else
System.out.println("Connection Already Established!");
System.out.println("Establish is ending...");
return conn;
} // End of Establish
确保MySQL连接器.jar文件位于类路径环境变量中。IDE,比如NetBeans,有时可以帮助您在IDE中将.jar文件放入类路径。您需要使用-cp选项运行应用程序,或者将其添加到类路径环境变量中。