Hello,
I have just started Java programing and am trying to create a java bean that connect to a MySQL database. The program compiles fine with no error but when I attempt to run the program I am getting the following error:
Exception in thread "main" java.lang.NoSuchMethodError: main
I have verified connectivity to the database using another Java program.
Am using jdk1.3.0_02 and Windows 2000 professional. I downloaded an example I wound on the Internet and adapted it to connect to the MySQL batabase with the same results.
Please help.
/**
* A test class using a simple database query.
*/
/* Standard java imports. */
import java.lang.*;
import java.sql.*;
public class SimpleDatabaseBean
{
String firstNme = "";
String lastName = "";
/**
* Run the query.
*/
public void runQuery()
throws Exception
{
/* Use JDBC to connect to the SAMPLE database.*/
Class.forName("com.mysql.jdbc.Driver"
.newInstance();
String url = "jdbc:mysql:time_clock";
String dbUser = "somename";
String dbPass = "apassword";
Connection dbConn = DriverManager.getConnection(url,dbUser,dbPass);
/* If the connection fails, throw an Exception.*/
if(dbConn == null)
{
throw new Exception("The database connection failed."
;
}
/* Build a SQL SELECT statement.*/
String sqlSelect = "SELECT FIRSTNME, LASTNAME FROM EMPLOYEE WHERE EMPNO = '000020'";
/* Run the SELECT statement.*/
Statement statement = dbConn.createStatement();
ResultSet result = statement.executeQuery(sqlSelect);
/* Get the result row.*/
while(result.next())
{
firstNme = result.getString("FIRSTNME"
;
lastName = result.getString("LASTNAME"
;
}
/* Close the connection.*/
dbConn.close();
}
/**
* Return the firstNme.
*/
public String getFirstNme()
{
return firstNme;
I have just started Java programing and am trying to create a java bean that connect to a MySQL database. The program compiles fine with no error but when I attempt to run the program I am getting the following error:
Exception in thread "main" java.lang.NoSuchMethodError: main
I have verified connectivity to the database using another Java program.
Am using jdk1.3.0_02 and Windows 2000 professional. I downloaded an example I wound on the Internet and adapted it to connect to the MySQL batabase with the same results.
Please help.
/**
* A test class using a simple database query.
*/
/* Standard java imports. */
import java.lang.*;
import java.sql.*;
public class SimpleDatabaseBean
{
String firstNme = "";
String lastName = "";
/**
* Run the query.
*/
public void runQuery()
throws Exception
{
/* Use JDBC to connect to the SAMPLE database.*/
Class.forName("com.mysql.jdbc.Driver"
String url = "jdbc:mysql:time_clock";
String dbUser = "somename";
String dbPass = "apassword";
Connection dbConn = DriverManager.getConnection(url,dbUser,dbPass);
/* If the connection fails, throw an Exception.*/
if(dbConn == null)
{
throw new Exception("The database connection failed."
}
/* Build a SQL SELECT statement.*/
String sqlSelect = "SELECT FIRSTNME, LASTNAME FROM EMPLOYEE WHERE EMPNO = '000020'";
/* Run the SELECT statement.*/
Statement statement = dbConn.createStatement();
ResultSet result = statement.executeQuery(sqlSelect);
/* Get the result row.*/
while(result.next())
{
firstNme = result.getString("FIRSTNME"
lastName = result.getString("LASTNAME"
}
/* Close the connection.*/
dbConn.close();
}
/**
* Return the firstNme.
*/
public String getFirstNme()
{
return firstNme;