关于jsp使用数据源的问题,请问有人知道出现了什么错误? 我的数据库的名字:mysql user:dbuserpassword:1234 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 呵呵给您测试类import java.sql.*;/* * * Created on 2006-8-26 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates *//** * @author Administrator * * TODO To change the template for this generated type comment go to Window - * Preferences - Java - Code Style - Code Templates */class testjdbc { /** * */ public static void main(String[] args) { System.out.println("HELLO"); System.out.println("ok"); try{ System.out.println("ok"); Class.forName("com.mysql.jdbc.Driver"); System.out.println("OK"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root&password=1234"); Statement st = con.createStatement(); ResultSet rs=st.executeQuery("select * from test"); //ResultSet rs=st.executeQuery("INSERT INTO `test` (`Id`,`test`) VALUES (null,2)"); while(!rs.isLast()){ rs.next(); System.out.println("test:" +rs.getString("id"));// 请在test数据库中建立表test(字段为id和test) System.out.println("0000ok" ); } rs.close(); con.close( ); } catch(Exception e){ e.printStackTrace(); } } } jsp比较难调试的!用j2se编译呵呵 谢谢xblue3(http://my.6cncn.cn) 我现在的问题是我不用数据源来连接的时候是没有问题的直接的class.forname来连接是没有任何的问题的但是使用数据源就出错了我在 Context context=new InitialContext(); DataSource ds=(DataSource)context.lookup("java:comp/env/jdbc/mysql");在后面加一个检查ds的语句结果显示能连接到ds的 大家知道是怎么回事吗??谢谢大家!虚心向大家请教 <parameter> <name>url</name> <value>jdbc:mysql://localhost:3306/mysql?autoReconnect=true</value> </parameter>-------------------------------------------------可能这个参数有问题 关于nutch1.4的问题!!!!!!! could not open ServletContext struts2 国际化配置 struts2常用些什么呢 hibernate+spring分页的问题 求助 JSP页面传值 netbeans6.1配置struts2出现问题 JAVA如何读取CSV,DBF文件? 请教jsf组件定制的问题? 关于ajax,服务器返回中文时乱码 如何设定JBOSS指向域名 hibernate 写入性能暴差,如何配置
import java.sql.*;
/* *
* Created on 2006-8-26
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*//**
* @author Administrator
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
class testjdbc { /**
*
*/
public static void main(String[] args) {
System.out.println("HELLO");
System.out.println("ok");
try{
System.out.println("ok");
Class.forName("com.mysql.jdbc.Driver");
System.out.println("OK");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root&password=1234");
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("select * from test");
//ResultSet rs=st.executeQuery("INSERT INTO `test` (`Id`,`test`) VALUES (null,2)");
while(!rs.isLast()){
rs.next();
System.out.println("test:" +rs.getString("id"));// 请在test数据库中建立表test(字段为id和test)
System.out.println("0000ok" );
}
rs.close();
con.close( );
}
catch(Exception e){
e.printStackTrace();
}
}
}
用j2se编译呵呵
我现在的问题是
我不用数据源来连接的时候是没有问题的
直接的class.forname来连接是没有任何的问题的
但是使用数据源就出错了
我在 Context context=new InitialContext();
DataSource ds=(DataSource)context.lookup("java:comp/env/jdbc/mysql");
在后面加一个检查ds的语句
结果显示能连接到ds的
大家知道是怎么回事吗??
谢谢大家!
虚心向大家请教
<name>url</name>
<value>jdbc:mysql://localhost:3306/mysql?autoReconnect=true</value>
</parameter>
-------------------------------------------------
可能这个参数有问题