当前位置: 技术问答>java相关
mysql的jdbc连接问题,请指教!!!
来源: 互联网 发布时间:2015-07-01
本文导语: rowset.jar和mm.mysql-2.4.0-bin.jar已经设置到CLASSPATH中, 我的db_mysql.java中: private boolean conn(){ try { Class.forName("org.gjt.mm.mysql.Driver"); this.conn = DriverManager.getConnection(this.urls,this.user,this.password); this.stmt =...
rowset.jar和mm.mysql-2.4.0-bin.jar已经设置到CLASSPATH中,
我的db_mysql.java中:
private boolean conn(){
try {
Class.forName("org.gjt.mm.mysql.Driver");
this.conn = DriverManager.getConnection(this.urls,this.user,this.password);
this.stmt = conn.createStatement();
Save_log("conn is ok");
return true;
}catch(SQLException ex){
Save_log("Error is "+ex.getMessage());
System.out.println(ex.getMessage());
return false;
}catch(java.lang.ClassNotFoundException e){
System.out.println("class not found "+e.getMessage());
Save_log(e.getMessage());
return false;
}
}
当我每次调用db_mysql.class时,他都会出错,而且在我的日志上记录如下:Server configuration denies access to data source。
我的ulrs,name,password都是正确的。请问我到底忽略了什么?
我的db_mysql.java中:
private boolean conn(){
try {
Class.forName("org.gjt.mm.mysql.Driver");
this.conn = DriverManager.getConnection(this.urls,this.user,this.password);
this.stmt = conn.createStatement();
Save_log("conn is ok");
return true;
}catch(SQLException ex){
Save_log("Error is "+ex.getMessage());
System.out.println(ex.getMessage());
return false;
}catch(java.lang.ClassNotFoundException e){
System.out.println("class not found "+e.getMessage());
Save_log(e.getMessage());
return false;
}
}
当我每次调用db_mysql.class时,他都会出错,而且在我的日志上记录如下:Server configuration denies access to data source。
我的ulrs,name,password都是正确的。请问我到底忽略了什么?
|
这是你连接字串错误,不允许。
|
url = "jdbc:mysql://" + servername + ":" + databasename;
|
Driver myDriver = (Driver) Class.forName(jdbcDriver).newInstance();
Properties props = new Properties();
props.put("user", username);
props.put("password", passwd);
props.put("server", "192.168.1.39:3306:sfscdb");
conn = myDriver.connect(dbURL, props);
stmt = conn.createStatement();
Properties props = new Properties();
props.put("user", username);
props.put("password", passwd);
props.put("server", "192.168.1.39:3306:sfscdb");
conn = myDriver.connect(dbURL, props);
stmt = conn.createStatement();