Net Beans and JDBC Problem
Hi everybody, I am able to compile and run a program that uses the JDBC withing the Netbeans environment.(I developed the application within that ide). However after building the project, if i try to run it from the command prompt or from windows it does not work . If i run it from the command prompt, I get this error message below. What do I need to do to be able to run the program outside the environment.
C:\>java -jar "D:\FinalProject\FinalProject\dist\FinalProject.jar"
Exception in thread "main" java.lang.NoClassDefFoundError: com/mysql/jdbc/Driver
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at utilitly.DBConnectAndUtilities.<init>(DBConnectAndUtilities.java:50)
at gui.mpisGui.<init>(mpisGui.java:23)
at finalproject.Main.createAndShowGui(Main.java:24)
at finalproject.Main.main(Main.java:35)
below is the code i use for the database linking and interaction.
import java.awt.Component;
import java.awt.event.ActionListener;
import java.sql.*;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.Timer;
import java.util.Vector;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.text.MaskFormatter;
/**
*
* @author Morrizle
*/
public class DBConnectAndUtilities{
/**declare a connection that would be used*/
private Connection dbcon;
private Statement dbstmt;
private ResultSet dbset;
private String dbName = "mpisdb";
private String patient_pers_info = "patient_pers_info";
/**
* Creates a new instance of DBConnectAndUtilities
*/
public DBConnectAndUtilities() {
//this.dbName = dbName;
/*load the driver and make a active connection/
*/
try{
/*load driver*/
Class.forName("com.mysql.jdbc.Driver").newInstance();
/*get an active connection*/
dbcon = DriverManager.getConnection("jdbc:mysql://localhost/" + dbName , "root","morrfo");
/*create a statement with which we can execute the update of database*/
dbstmt = dbcon.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
/*prints the following if the connection is succesfully made with the database*/
//System.out.println("Connection made");
}
catch(Exception m){
/*prints the trace of errors if the connection or loading of driver doesn't work*/
m.printStackTrace();
}
}
/*methods to update the database and tables
returns true when the update is successful **/
public boolean updateDB(String tableNValues){
/*execute*/
boolean result = false;
try{
dbstmt.executeUpdate(tableNValues);
result = true;
}catch(SQLException k){
k.printStackTrace();
}
return result;
}
/*method to execute queries*/
public ResultSet queryDB(String query){
ResultSet m = null;
try{
m = dbstmt.executeQuery(query);
}catch(SQLException q){
q.printStackTrace();
}
return m;
}
/*method to close the connection*/
public void closeConnection(){
try {
dbcon.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public void closeStatement(){
try {
dbstmt.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
/*a utility method to return a varchar object as a string*/
/* method to convert a string to varchar*/
public String toVarchar(String convert){
String converter = "";
if(convert.isEmpty()){
converter = null;
}else{
converter = "'"+ convert +"'";
}
return converter;
}
}
Please come to my aid . Please.!!!!!!!!!!!!!!!!! i need urgent help

