jdbc:mysql://"+host+":"+port+"/"+db_name

解决方案 »

  1.   

    import java.sql.*;
    public class Cnn
    {
        public static void main(String args[])
        {
             String driver="你的驱动位置";
             String url="jdbc:mysql://localhost:3306/你的数据库名";
             String user="你的用户名";
             String pwd="密码";
             try
             {
                    Class.forName(driver);
             }
             catch(Exception E)
             {
                    System.out.println("Fail to load Driver"+driver);
                    E.printStackTrace();
             }
             try
             {
                    Connection con=DriverManager.getConnection(url,user,pwd);
                    
                    while(con!isClose())
                    {
                          System.out.println("Success");
                    }
                    con.close();
             }
             catch(SQLException SE)
             {
                    SE.printStackTrace();
             }
        }
    }
      

  2.   

    for example:
    private static String s_JDBCUrl = "jdbc:mysql://" + DB_HOST + ":" + JDBC_PORT + "/" + DB_NAME; 
    private static final String DB_HOST = "localhost";
    private static final String JDBC_PORT = "3306";
    private static final String DB_NAME = "vap";
    connection  = DriverManager.getConnection(s_JDBCUrl, user, password);