Home > Back-end >  Inquire, this idea of database connection is what went wrong
Inquire, this idea of database connection is what went wrong

Time:09-22

Idea is the community edition jar package is added in structure of

CodePudding user response:

Are there any normal load drive: Class. Class.forname (driver) this sentence

CodePudding user response:

What do you think is normal load excuse me

CodePudding user response:

refer to the second floor m0_46357566 response:
could you tell me how to see whether the normal load


Want to post all the procedures, can not see your url,

CodePudding user response:

Will break points, database connection just a few steps, the Class. The class.forname (driver), the other is to load drivers, if it runs through the console no error, drivers should have no problem, then to the finish line 29 operation, an error, is there is something wrong with the connection, you first use the CMD or local tools even once, sure no problem to put information added here

CodePudding user response:

reference qq_39936465 reply: 3/f
Quote: refer to the second floor m0_46357566 response:

How can I see whether normal load


To post all the procedures, can not see your url,
package cn. Campsg. Gm service;

The import cn. Campsg. Gm. The entity. The User;
The import com. Mysql. JDBC. Exceptions. MySQLDataException;

import java.sql.*;

Public class UserDaoDB implements UserDao {
Public static final String url="JDBC: mysql://127.0.0.1/goods";
Public static final String driver=". Com. Mysql. JDBC driver ".
Public static final String loginUser="root";
Public static final String loginPassword="0514";
@ Override
Public User login (String uid, String PWD) {
Try {//1
Class.forName(driver);
} the catch (a ClassNotFoundException e) {
e.printStackTrace();
}

User User=null;

String SQL="SELECT * FROM the USER WHERE the UID=? AND PASSWORD=?" ;
Connection conn=null;
PreparedStatement CMD=null;
The ResultSet result=null;

Try {
Conn=DriverManager. GetConnection (url, loginUser, loginPassword);
CMD=conn. PrepareCall (SQL);
CMD. SetString (1, uid);
CMD. SetString (2, PWD);
Result=CMD. ExecuteQuery ();

If (result. The next ()) {
User=new user ();
User. SetId (result. Get string (" uid "));
User. Elegantly-named setName (result. Get string (" name "));
User. SetSex (result. GetByte (" sex "));
User. SetPassword (result. Get string (" password "));
User. SetCity (result. Get string (" city "));

}
return user;
} the catch (SQLException e) {
e.printStackTrace();
return null;
} the finally {
Try {
If (conn!=null & amp; & ! Conn. IsClosed ())
conn.close();
} the catch (SQLException e) {
e.printStackTrace();
return null;
}
}
}
}

CodePudding user response:

There was an obvious error you this url, port 3306 fewer JDBC: mysql://127.0.0.1:3306/goods

CodePudding user response:

refer to 6th floor potato is my favorite response:
there was an obvious error you this url, port 3306 fewer JDBC: mysql://127.0.0.1:3306/goods
thank just add checked but it's still wrong before
  • Related