谁有用过JDBC连MYSQL数据库的经验??

city_goal 2003-03-08 06:36:43
做东西,连MYSQL数据库总是出错,请赐教。。
classpath中已经正确包含了了mysql驱动。。
测试页代码如下:
<%@ page contentType="text/html;charset=gb2312" %>
<%
java.sql.Connection conn;
java.lang.String strConn;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
sqlConn= java.sql.DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
%>

却提示出错,提示的信息就不用贴了,贴了也看不懂。。。
...全文
28 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
city_goal 2003-03-09
  • 打赏
  • 举报
回复
放到CLASSPATH,已经顺利连接好了,谢谢
不过,在进行查询的时候出错,如下
<%@ page contentType="text/html;charset=gb2312" %>
<%
java.sql.Connection sqlConn=null;
java.sql.Statement stmt;
java.sql.ResultSet rs;

Class.forName("org.gjt.mm.mysql.Driver").newInstance();
sqlConn= java.sql.DriverManager.getConnection("jdbc:mysql://localhost/bbs","root","");
try{
stmt=sqlConn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=stmt.executeQuery("select * from t1");

while (rs.next()) {
Sring time=rs.getString(a);
System.out.println(time);
}
stmt.close();
sqlConn.close();
}
catch(SQLException e){System.out.println(e.toString());}

%>
xby45 2003-03-08
  • 打赏
  • 举报
回复
把你的mm.mysql-2.0.14-bin.jar放到CLASSPATH中,或者放到%JAVA_HOME%\jre\lib\ext下
city_goal 2003-03-08
  • 打赏
  • 举报
回复
哦,好明天就贴上错误的 代码信息,。。请3月9日看 。。
peacock_king 2003-03-08
  • 打赏
  • 举报
回复
Connection con;
Statement stmt;
ResultSet rs;
String url ="jdbc:mysql://localhost/test?user=root&password=&useUnicode=true&characterEncoding=GBK";

try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
//Class.forName("com.codestudio.sql.PoolMan").newInstance();
}catch(ClassNotFoundException e){
System.out.println(e.toString());
}catch(InstantiationException e){
System.out.println(e.toString());
}catch(IllegalAccessException e){
System.out.println(e.toString());
}
try{
con=DriverManager.getConnection(url);
if(con!=null){
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=stmt.executeQuery("select created_time from book where author_name='asdf'");

while (rs.next()) {
………………
}
stmt.close();
con.close();
}
else System.out.println("无效的连接");
}catch(SQLException e){System.out.println(e.toString());}
wang_zheng_wz 2003-03-08
  • 打赏
  • 举报
回复
贴出错误信息,有人能看懂
Namo 2003-03-08
  • 打赏
  • 举报
回复
如果是出现一堆错误提示的话,最有可能是CLASSPATH没有配置好。

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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