wood burning stoves 2.0*
The moose likes JDBC and the fly likes JDBC using ResourceBundle Class Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC using ResourceBundle Class Problem " Watch "JDBC using ResourceBundle Class Problem " New topic
Author

JDBC using ResourceBundle Class Problem

Nirlep Patel
Greenhorn

Joined: Jul 29, 2007
Posts: 7
hi

I am facing ClassNotFoundException problem

I am using NetBeans 5.5 IDE and using ResourceBunlde Class.

My code is: Main.java

package resobundledb;
import java.sql.*;
import java.util.*;

public class Main {

public static void main(String argv[]) {
Connection con = null;
//ResultSet rs;
ResourceBundle bundle = ResourceBundle.getBundle("dbresource");
System.out.println("Hello this is resourcebundle database connectivity 01");
System.out.println();

try{

String url = bundle.getString("URL");
System.out.println("url is: " + url);
Statement stmt;
ResultSet rs;

System.out.println("Driver is: " + bundle.getString("Driver"));
/* Load the Driver Class. */
Class.forName(bundle.getString("Driver"));
//Class.forName(java.util.ResourceBundle.getBundle("resobundledb/dbresource").getString("Driver"));

System.out.println("Hello this is resourcebundle database connectivity 02");
//here is where the connection is made
con = DriverManager.getConnection(url, java.util.ResourceBundle.getBundle("resobundledb/dbresource").getString("root"), java.util.ResourceBundle.getBundle("resobundledb/dbresource").getString("password"));
//con = DriverManager.getConnection(url, "root", "password");
System.out.println("Hello this is resourcebundle database connectivity 03");
stmt = con.createStatement();

//rs = stmt.executeQuery(java.util.ResourceBundle.getBundle("resobundledb/dbresource").getString("select_*_from_tbluser"));
rs = stmt.executeQuery("select * from tbluser");

System.out.println("This is the result: ");
System.out.println();

while(rs.next()){
//int uid = rs.getInt("uid");
int uid = rs.getInt(1);

//String username = rs.getString("username");
String username = rs.getString(2);

//String name = rs.getString("name");
String name = rs.getString(4);

//String bdate = rs.getString("birthdate");
String bdate = rs.getString(5);

//double sscper = rs.getDouble("sscpercentage");
double sscper = rs.getDouble(6);

//double fees = rs.getDouble("fees");
double fees = rs.getDouble(7);

//String lastaccesstime = rs.getString("lastaccessedtime");
String lastaccesstime = rs.getString(8);

System.out.println("User id: " + uid);
System.out.println("User Name: " + username);
System.out.println("Name: " + name);
System.out.println("Birth Date: " + bdate);
System.out.println("SSC Percentage: " + sscper + " %");
System.out.println("Fees: " + "Rs. " + fees);
System.out.println("Last Accessed Time: " + lastaccesstime);
}
stmt.close();
}
catch( SQLException e ) {
System.out.println("it is printing from SQLException");
e.printStackTrace();
}
catch(ClassNotFoundException e){
System.out.println("it is printing from ClassNotFoundException");
System.out.println(e.getMessage());
}
finally {
if( con != null ) {
try { con.close(); }
catch( Exception e ) { }
}
}
}
}
-----------------------------------------------------------------------------------------------------
My properties file is: dbresource.properties

Driver=com.mysql.jdbc.Driver
URL=jdbc:mysql://localhost:3306/test
select_*_from_tbluser=select * from tbluser
password=password
root=root
-----------------------------------------------------------------------------------------------------
My database name is: tbluser

and it has following fields.

userid, username, password, name, birthdate, sscpercentage, fees, lastaccessedtime


I tried a lot since from last 2 days but could not get it.

still i am trying... if someone know help me

thanks


regards, nirlep
discuss.teaching@gmail.com, http://www.learnclinux.com
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You need to divide and conquer. Firstly, your app is too long. Solve the connection issue and then look at the rest.

1) Can you prove your properties file is being found
2) can you prove the Driver string value is read?
3) Can the application find the class on the classpath?

You haven't demonstrated that you can answer any of these, and at least one is failing.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"Nirlep" please check your private messages.

Dave.
 
 
subject: JDBC using ResourceBundle Class Problem