亚洲style 2015-04-13 13:55 采纳率: 0%
浏览 1516

求各路大神们帮帮小弟,数据库连接除了问题

package jk.action;

/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor. */

/**
*

  • @author Administrator
    /
    import java.sql.
    ;
    public class link {
    String userName="root";
    //密码
    String userPasswd="123456";
    //数据库名
    String dbName="tushuguanli";

    Connection con;
    public Statement st;
    public ResultSet rs;

    public link(){////用来链接mysql数据库的类,其他Action类可以调用它来完成对数据库的操作
    try{
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    //String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
    String url="jdbc:mysql://localhost:3306/dbName?user=root&password=userPasswd";
    Connection con=DriverManager.getConnection(url);
    Statement st=con.createStatement();

    }

    catch(java.lang.Exception e)
    { 
        System.out.println("Link DB error "+e.getMessage());        
    }
    

    }

}

  • 写回答

3条回答 默认 最新

  • oyljerry 2015-04-13 14:11
    关注

    先把链接字符串打印出来,然后看你拼接对了没?估计字符串组合不对。

    评论

报告相同问题?

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿