I have developed a program where I do some database connections and send some queries with JDBC.
I have used MySQL, NetBeans 6.9 under Ubuntu开发者_如何学JAVA 11.04 as platform. When I run the app from NetBeans, it works perfectly but when I try to run it from terminal I get SQL Exception. This is the function that produces that SQL Exception. The program terminates before "Establish is ending" line.
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
Make sure the MySQL Connector .jar file is in your classpath environment variable. IDEs, like NetBeans, sometimes help you out with putting .jar files in the classpath while you're in the IDE. You'll either need to run your app with the -cp option, or add it to your classpath environment variable.
精彩评论