Tomcat Connect DB2 via JDBC

xiaoxiao2021-03-06  22

These two days have been familiar with DB2, and also tried to connect DB2 servers through JDBC. According to the previous experience, the connection is unsuccessful. Class.Forname ("com.ibm.db2.jdbc.app.db2driver"). NewInstance (); string url = "jdbc: db2: // localhost: 5000 / sample"; // Sample for your database name String User = "admin"; string password = ""; connection conn = drivermanager.getConnection (URL, User, Password); Total NO Suitable Driver is very depressed, I don't know what is going on. I just started looking for my colleagues, he is not very familiar. Finally, only the old way, put the mistake in Google search. It seems that this mistake is quite common. I opened the DB2 JAR package and started looking for com.ibm.db2.jdbc.app.db2driver classes, actually did not find it. There is an article on the Internet tells me to go to the installation directory below / sqllib / java12 run JDBC20.exe, then get a db2java.zip, there is this class. However, the package CoM actually wrote (depressed), no matter, first. Or not. A lot of explanations are incorrect. Below this paragraph gives me a little revelation. BECAUSE There Are Four Types of JDBC Driver. To DB2, URL = JDBC: DB2: DatabaseName Is for Type 2 Driver, URL = JDBC: DB2: // Host / DatabaseName Is for Type 4 Driver. You Can Reference DB2 J2EE MANUAL, WHICH Will Tell You How To Use Them, Each Type Driver Has Its Own Driver Class. Finally, I opened the db2jcc.jar package, see com.ibm.db2.jcc.db2driver driver, actually made me test success. Here is my connection code. Class.Forname ("com.ibm.db2.jcc.db2driver"). NewInstance (); string url = "jdbc: db2: // ip: port / dbname"; string user = "user"; string password = "Password "; System.out.Println (" Connecting to Database URL = " URL); Connection Conn = DriverManager.getConnection (URL, User, Password);

转载请注明原文地址:https://www.9cbs.com/read-65571.html

New Post(0)