xzxmustwin
2016-12-20 12:08
采纳率: 50%
浏览 1.9k

myeclipse用jdbc连接mysql数据库

package com;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBTest {
/**

  • @param args
    */

    private static final String url="jdbc:mysql://localhost:3306/db_shop";
    private static final String name="root";
    private static final String password="root";

    static{
    try {
    //加载驱动程序;
    Class.forName("com.mysql.jdbc.Driver");
    //获得数据库连接;
    }catch(ClassNotFoundException e){
    e.printStackTrace();
    }
    }
    public static void main(String[] args){
    try{
    Connection conn=DriverManager.getConnection(url,name,password);
    System.out.println("数据库连接成功"+conn);
    }catch(SQLException e){
    e.printStackTrace();
    }
    }

    New Database Connection Driver中Test Driver出现Error while performing database login with the db_shop driver:Unable to create connection.Check your URL.

7条回答 默认 最新

相关推荐 更多相似问题