This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes ClassNotFoundException with ResourceBundle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ClassNotFoundException with ResourceBundle" Watch "ClassNotFoundException with ResourceBundle" New topic
Author

ClassNotFoundException with ResourceBundle

Nirlep Patel
Greenhorn

Joined: Jul 29, 2007
Posts: 7
Dear friends

I am using NetBeans IDE 5.5 and facing problem in Database Connectivity using ResourceBundle Class.


This is the Code of 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. */ Problem is here
Class.forName(bundle.getString("Driver")); -Problem is here
//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("nipatel"));
//con = DriverManager.getConnection(url, "root", "nipatel");
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 ) { }
}
}
}
}
------------------------------ ------------------------------ ------------------------------ ------------------------------ --------------

This is my dbresource.properties file

Driver=com.mysql.jdbc.Driver
URL=jdbc:mysql://localhost :3306/test
select_*_from_tbluser=select * from tbluser
nipatel=nipatel
root=root

------------------------------ ------------------------------ ------------------------------ ------------------------------ --------------

This is my Database columns in MySQL

Column

Datatype
userid

int(11)
username

varchar(8)
password

varchar(8)
name

varchar(60)
birthdate

Date
sscpercentage

double(4,2)
fees

double(8,2)
lastaccessedtime

Date

------------------------------ ------------------------------ ------------------------------ ------------------------------ --------------

Output should be in this format

Userid: 1
Username: elitecore
Name: Elitecore
Birth date: 1st January, 2003
SSC Percentage: 88.1 %
Fees: Rs. 700.50
Last accessed time: 1st Jan 2003, 11:00 am



--
Regards
Nirlep


regards, nirlep
discuss.teaching@gmail.com, http://www.learnclinux.com
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

"discuss teaching",
Please check your Private Messages.

Thanks
Jeanne
JavaRanch Sheriff


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Please don't post the same question in multiple forums. It creates duplicate conversations and wastes the time of the people trying to help you.

Thanks,
Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassNotFoundException with ResourceBundle
 
Similar Threads
No suitable driver found for jdbc:oracle:thin:@localhost:1521:Indu
packages --- Not allowing me to access public class from the same package...
accessing one class from other
data mismatch error
JDBC using ResourceBundle Class Problem