search

Home  >  Q&A  >  body text

Class.forName(driverClass) not running

System.out.println("======1======");
Class.forName(driverClass);
conn = DriverManager.getConnection("xxxx"," xxxx","xxxx");
System.out.println("======2======");

This paragraph is written in try catch without any error

The operation can print out ======1======
But in Class.forName(driverClass); the card owner
cannot print out======2=== ===

There are no errors in the whole process, but the conn cannot be obtained, and it is stuck in Class.forName
The jars are also under the classpath. If classnotfound, it will be caught by exception

滿天的星座滿天的星座2774 days ago724

reply all(6)I'll reply

  • 怪我咯

    怪我咯2017-05-17 10:10:27

    Dear, is there something wrong with the compiler? Can you just use the java command to compile and execute it?

    reply
    0
  • PHP中文网

    PHP中文网2017-05-17 10:10:27

    Are you sure you have something written in your catch?

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-17 10:10:27

    Change

    Class.forName(driverClass) to
    Class.forName(driverClass).newInstance() and try it

    reply
    0
  • 某草草

    某草草2017-05-17 10:10:27

    It does not prove that it is stuck on the forName method. The probability of getting stuck on the getConnection method is much greater. This is to connect to the database.

    reply
    0
  • 为情所困

    为情所困2017-05-17 10:10:27

    YourClass.forName(driverClass); First, make sure you specify a specific path for the driverClass class you dynamically load;

    reply
    0
  • ringa_lee

    ringa_lee2017-05-17 10:10:27

    driverclass needs to be enclosed in double quotes "driverclass"

    reply
    0
  • Cancelreply