这个mysql连接字符串怎么写?

chendd2001 2003-05-20 08:55:57
MySQL 3.23.49a-log running on localhost as d278@localhost,这是我在服务器上看到的提示。我得数据库是dbtest, 那么是否url这样写
jdbc:mysql://localhost/dbtest(好像说我无权访问数据源,当然我密码也对的)
还是
jdbc:mysql://d278@localhost/dbtest(从错误反映看好像错了找不到host)
就是d27278@localhost把我搞湖了
...全文
43 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
snicker 2003-05-20
  • 打赏
  • 举报
回复
Class.forName("org.gjt.mm.mysql.Driver").newInstance();

后面的.newInstance()可以不要
snicker 2003-05-20
  • 打赏
  • 举报
回复
把你的user,password 添上试试

snicker 2003-05-20
  • 打赏
  • 举报
回复
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.SQLException;
import java.sql.DriverManager;

public class TestMysql {

public static void main(String[] args) {
Connection con= null;
Statement stmt = null;
ResultSet rs = null;
String url ="jdbc:mysql://localhost/query?useUnicode=true&characterEncoding=gb2312";
String user="";
String password="";
String queryString = "select code,name from cbm where code <='00000199'";
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
con= DriverManager.getConnection(url,user,password);
stmt = con.createStatement();
rs = stmt.executeQuery(queryString);
while(rs.next()){
System.out.println("code:"+rs.getString("code")+" name:"+rs.getString("name"));
}
}catch(SQLException e){
System.out.println(" "+e);
}catch(Exception e){
System.out.println(" "+e);
}finally{
try{
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (con != null) con.close();
}catch(SQLException e){
System.out.println(" error in finally"+e);
}
}
}
}

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧