JDBC of Java ①

JDBC tool preparation: MySQL (database), MyEclipse (development tool), Navicat (database management tool) JDBC programming steps · loading driver: class. Forname (driverclass); Load MySQL driver class Forname ("com. Mysql. JDBC. Driver") loads the Oracle driver class Forname ("oracle. JDBC. Driver. Oracledriver") · get the database connection: drivermanager getConnection("jdbc.MysqL://127.0.0.1:3306/imooc","root","root"); ==> The parameters are (URL, usename, password) · create statement object: conn.createstatement(); Public class dbutil {private static final string url = "JDBC: MySQL: / / 127.0.0.1:3306 / test"; private static final string user = "root"; private static final string password = "117528"; public static void main (string [] args) throws classnotfoundexception, sqlexception {/ / use Mysql to load the driver class.forname ("com. Mysql. JDBC. Driver") ; // Get a connection to the database connection conn = drivermanager getConnection(URL,USER,PASSWORD); // Operate the database through the connection of the database to add, delete, modify and query statement stmt = conn.createstatement()// Execute database statement resultset rs = stmt executeQuery("select user_name,age from meinv"); // If there is data, rs.next returns true, otherwise false while (rs.next()) {system.out.println (rs.getstring ("user_name") + "," + rs.getint ("age"));}}}} report errors:

  Exception in thread "main" java. lang.ClassNotFoundException: com. MysqL. jdbc. driver at java. net. urlclassloader$1. run(urlclassloader.java:366) at java. net. urlclassloader$1. run(urlclassloader.java:355) at java. security. AccessController. doPrivileged(Native Method) at java. net. urlclassloader. findClass(urlclassloader.java:354) at java. lang.ClassLoader. loadClass(ClassLoader.java:425) at sun. misc. Launcher$AppClassLoader. loadClass(Launcher.java:308) at java. lang.ClassLoader. loadClass(ClassLoader.java:358) at java. lang.Class. forName0(Native Method) at java. lang.Class. forName(Class.java:190) at com. wuhao. JD. JDButil. main(JDButil.java:15)

Write the above program, connect to MySQL, import the MySQL driver package, or keep reporting errors. The reason is / / use MySQL and load the driver class forName("com.MysqL.jdbc.driver");

Here. Com MysqL. jdbc. The driver of the driver should be driver, ignoring the case.......

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>