jdbc:mysql://127.0.0.1:3306/test_: No suitable driver found for jdbc:mysql://127.0.0.1:3306/bank

今天遇到个很奇怪的问题,项目登录上去之后,去修改某张表的一条记录,突然报错:No suitable driver found for jdbc:mysql://127.0.0.1:3306/bank。项目可以登录,那就不是数据库配置文件的问题。其他表的添加修改也可以,那说明数据库的连接也没问题。真搞不懂怎么回报这个错。请大神们指点一二。我感激不仅!

数据库配置文件:

driver=com.mysql.jdbc.Driver

url=jdbc\:mysql\://127.0.0.1\:3306/bank

#url=jdbc:mysql://127.0.0.1:3306/jdbcstudy

userName=root

password=1234

数据库连接类:

public class JdbcUtils implements Serializable {

private static String driver;

private static String url;

private static String userName;

private static String password;

private static JdbcUtils jdbcUtil=null;

/**

* 单例模式获取实例

*/

private JdbcUtils(){

//读取db.properties文件中的数据库连接信息

InputStream in=JdbcUtils.class.getClassLoader().getResourceAsStream("DB.properties");

Properties prop=new Properties();

try {

prop.load(in);

//获取数据库连接驱动

driver=prop.getProperty("driver");

//获取数据库连接URL地址

url=prop.getProperty("url");

//获取数据库连接用户名

userName=prop.getProperty("userName");

//获取数据库连接密码

password=prop.getProperty("password");

//加载数据库驱动

Class.forName(driver);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}finally{

try {

if(in!=null){

in.close();

}

} catch (IOException e) {

e.printStackTrace();

}

}

}

public static JdbcUtils createInstance(){

if(jdbcUtil==null){

jdbcUtil=new JdbcUtils();

}

return jdbcUtil;

}

/**

* 获取数据库的连接对象

* @return

*/

public static Connection getCon() throws SQLException{

return DriverManager.getConnection(url, userName, password);

}

/**

* 释放资源

* 要释放的资源包括Connection数据库连接对象,负责执行SQL命令的Statement对象,存储查询结果的ResultSet对象

* @param con

* @param st

* @param rs

*/

public static void release(Connection con,Statement st,ResultSet rs){

if(rs!=null){

try {

rs.close();

} catch (SQLException e) {

e.printStackTrace();

}

}

if(st!=null){

try {

st.close();

} catch (SQLException e) {

e.printStackTrace();

}

}

if(con!=null){

try {

con.close();

} catch (SQLException e) {

e.printStackTrace();

}

}

}

}

操作类的方法:

public WorkFlowTable getWorkFlowTable(int id) {

Connection con=null;

PreparedStatement ps=null;

ResultSet rs=null;

WorkFlowTable wfTable=null;

try {

con=JdbcUtils.createInstance().getCon();//报错点

StringBuffer sql=new StringBuffer("select wt.id wtid,wt.thetable wttable,wt.tablename wttablename,work_id,wt.description wtdes,wf.id wfid ,wf.name wfname, wf.workflowprocess wfprocess ,wf.notes wfnotes,wf.flag wfflag from tb_workflow_table wt left join tb_workflow wf on wt.work_id=wf.id where wt.id=? ");

ps=con.prepareStatement(sql.toString());

ps.setInt(1, id);

rs=ps.executeQuery();

while (rs.next()) {

wfTable=new WorkFlowTable();

wfTable.setId(rs.getInt("wtid"));

wfTable.setThetable(rs.getString("wttable"));

wfTable.setTableName(rs.getString("wttablename"));

wfTable.setDescription(rs.getString("wtdes"));

WorkFlow wf=new WorkFlow();

wf.setId(rs.getInt("wfid"));

wf.setName(rs.getString("wfname"));

wf.setWorkingProcess(rs.getString("wfprocess"));

wf.setNotes(rs.getString("wfnotes"));

wf.setFlag(rs.getString("wfflag"));

wfTable.setWf(wf);

}

} catch (SQLException e) {

e.printStackTrace();

}finally{

JdbcUtils.release(con, ps, rs);

}

return wfTable;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值