谁有用过JDBC连MYSQL数据库的经验?? 如果是出现一堆错误提示的话,最有可能是CLASSPATH没有配置好。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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());} 把你的mm.mysql-2.0.14-bin.jar放到CLASSPATH中,或者放到%JAVA_HOME%\jre\lib\ext下 放到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());}%> servlet中oracle 分页 请问怎么在Tomcat6.0中配置Oracle数据源? 网络爬虫!~~~求救 关于jasperreport参数的问题(成批打印的时候) 高手帮忙看一下?(在线等) jsp如何在页面之间传递事件? 邮件在内网只能收不能发的问题。 这个jsp问题如何解决,求高手! 关于一个时间倒计数的线程 jxl 如何设置页边距! 在做jsp+javabean时为何感觉不到java是面向对象的 linux下的oracle与access问题!
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());}
不过,在进行查询的时候出错,如下
<%@ 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());}%>