2014年1月7日星期二

Connect to the database problem

Connection conn = (Connection) DriverManager.getConnection (url, user, password);
Why when I connect to the database here are tips I need a strong turn, I do not need to read the book , seeking to explain , thank you.
------ Solution ---------------------------------------- ----
java objects in all , the result of natural objects to turn into a previously defined object types ,
------ Solution ------------ --------------------------------
you right in front of the Connection is java.sql.Connection ? not, turn on the prompt strong , but not easy to turn the estimated completion
------ Solution --------------------- -----------------------
your Connection is java.sql.Connection it? I think you quoted the wrong object is not so strong you just want to turn ah
------ Solution ------------------------ --------------------
halo upstairs actually told me the same thing
------ Solution ------- -------------------------------------
you this test class name written Connection bar, so try java.sql.Connection conn = DriverManager.getConnection (url, user, password);
------ Solution ------------------- -------------------------
JDK inside it a Connection Interface , DriverManager.getConnection Connection type is returned , no strong turn


------ Solution ------------------------------------ --------
you import a database package may be wrong (import com.mysql.jdbc.Connection ;). I use mysql database, import the package is ( import java.sql.Connection; )
------ For reference only ---------------------- -----------------
import com.mysql.jdbc.Connection; indeed imported wrong, thank you

没有评论:

发表评论