struts下:
struts-config.xml:
<data-sources>
<data-source key="dataSource">
<set-property value="false" property="autoCommit" />
<set-property value="Example Data Source Configuration" property="description" />
<set-property value="oracle.jdbc.driver.OracleDriver" property="driverClass" />
<set-property value="10" property="maxCount" />
<set-property value="2" property="minCount" />
<set-property value="jdbc:oracle:thin:@210.29.175.252:1521:account" property="url" />
<set-property value="temp" property="password" />
<set-property value="temp" property="user" />
</data-source>
</data-sources>action:DataSource dataSource=servlet.findDataSource("dataSource");
Connection conn = dataSource.getConnection();
String sSQLHOMEWORK = "SELECT * FROM testtable";
PreparedStatement ps = conn.prepareStatement(sSQLHOMEWORK);
ps.setString(1,user.get(0).toString());//把?参数加进来
ResultSet sqlRst = ps.executeQuery();
struts-config.xml:
<data-sources>
<data-source key="dataSource">
<set-property value="false" property="autoCommit" />
<set-property value="Example Data Source Configuration" property="description" />
<set-property value="oracle.jdbc.driver.OracleDriver" property="driverClass" />
<set-property value="10" property="maxCount" />
<set-property value="2" property="minCount" />
<set-property value="jdbc:oracle:thin:@210.29.175.252:1521:account" property="url" />
<set-property value="temp" property="password" />
<set-property value="temp" property="user" />
</data-source>
</data-sources>action:DataSource dataSource=servlet.findDataSource("dataSource");
Connection conn = dataSource.getConnection();
String sSQLHOMEWORK = "SELECT * FROM testtable";
PreparedStatement ps = conn.prepareStatement(sSQLHOMEWORK);
ps.setString(1,user.get(0).toString());//把?参数加进来
ResultSet sqlRst = ps.executeQuery();
解决方案 »
- 怎么在href中提交数据?
- 疑惑:ResultSet.close()后,生成 ResultSet 对象的 Statement 对象和 Connection 对象不调用close,连接池会继续占用吗?
- 遇到一个超级怪异的问题!
- 有对struts精通的高手吗,谢谢
- 初学struts,急于想知道的问题,请高手指教
- 初学:那错了
- 数据库性能优化问题(在线等)
- 奇怪的汉语参数问题????
- 哪里有jfreechart的文档
- Connection reset by peer: JVM_recv in socket input stream read这个问题到底怎么解决??
- <tomcat与java web开发技术详解>,孙卫琴/著,哪里有下载的!
- struts-config.xml配置数据源的问题,在线等
String url = "jdbc:oracle:thin:@localhost:1521:testdata"; //testdata为数据库的SID
String user = "test";
String password = "test";
conn = DriverManager.getConnection(url, user, password);
try
{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbcracle:thin:@192.168.2.4:1521:
oracle9";
//orcl为你的数据库的SID
String user="scott";
String password="tiger";
//String col1;
//String col2;
Connection conn= DriverManager.getConnection(url,user,password);
}
catch(ClassNotFoundException e)
{
throw new UnavailableException("jdbc driver not foune:"+jdbcDriver);
}
Statement stmt=conn.createStatement();
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SID
String user="test";
String password="test";
Connection conn= DriverManager.getConnection(url,user,password);