Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6326821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:09:48+00:00 2026-05-24T17:09:48+00:00

Using JDK1.6.0_16, I have this simple program where I am trying to get beanshell

  • 0

Using JDK1.6.0_16, I have this simple program where I am trying to get beanshell 2.0b4 to load a .jar dynamically (as the documentation suggests it will do) and I am having no luck. The documentation says that if I use beanshells’ getClass() method then it will load jars that were previously loaded by the “addClassPath()” method. It is not working. I need help on this…

//debug();
addClassPath("mysql-connector-java-5.1.15.jar"); 
import com.mysql.jdbc.Driver; 
import java.sql.Connection;  
import java.sql.DriverManager; 
import java.util.Arrays;

System.out.println("MySQL Connect Example.");
System.out.println("Classpath: " + Arrays.toString( getClassPath() ) + "\n");

Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "test";
String driver = "com.mysql.jdbc.Driver";
String userName = "root"; 
String password = "password";
try {
  Class driverClass = getClass( driver );
  if(driverClass != null) {
    Driver driver = driverClass.newInstance();
    if(driver != null) {
      DriverManager.registerDriver(driver);
    }
  }
  conn = DriverManager.getConnection(url+dbName,userName,password);
  System.out.println("Connected to the database");
  conn.close();
  System.out.println("Disconnected from database");
} catch (Exception e) {
  e.printStackTrace();
}

This problem I am having strongly suggests that the getClass() method (of beanshell) is unable to see its own dynamically changed classpath.

NOTE: this code works only when I put the mysql.jar file into the jre/lib/ext directory (which is where the legacy jre classloader can load it; not the beanshell classloader)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:09:49+00:00Added an answer on May 24, 2026 at 5:09 pm

    this is probably not a beanshell thing, jdbc has issues loading drivers across classloaders (check out the class javadoc for ClassLoader, and see hacks like this).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this real weird exception when issuing a basic SELECT, using MySQL 5.1.32-community
I have a 3rd party JAR file that is compiled using Java 1.4. Is
I have my JAVA_HOME set to: C:\Program Files (x86)\Java\jdk1.6.0_18 After I run maven install
I'm using intelliJ IDEA version 9.0.1 build #IU 93.94 with JDK 1.6.0_17. This error
In Eclipse 3.4.1 using JDK1.6.0_10 how can I activate a warning on a missing
Using online interfaces to a version control system is a nice way to have
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I've tried to run a Wicket app in an embedded Jetty, using this code:
i'm using teamcity 5.1.5.. trying to build an MSBuild project with an AfterDeploy target

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.