<%@ page contentType="text/html;charset=gb2312" import="java.sql.*"%>
<html>
<head>
<title> qin NO.4 </title>
<bdoy>
<jsp:useBean id="NinGoo" scope="page" class="NinGoo.dbconn1" />
<%
ResultSet rs=null;
Connection conn = null;
NinGoo.setServer("127.0.0.1"); //设置MySQL的服务器名或者IP
NinGoo.setPort("3306"); //设置MySQL的监听端口
NinGoo.setDB("mysql"); //设置MySQL的数据库名
NinGoo.setUser("root"); //设置连接MySQL的用户名
NinGoo.setPass("sjjifk"); //设置连接MySQL的密码
conn = NinGoo.getConn() ;
rs= NinGoo.executeSQL("select * from help_topic");
rs.next();
%>
Row:<%=rs.getString(3)%>
<%rs.next();%>
<%out.print("Successful!\n");%>
<%
rs.close();
conn.close();
%>
</body>
</html>
<html>
<head>
<title> qin NO.4 </title>
<bdoy>
<jsp:useBean id="NinGoo" scope="page" class="NinGoo.dbconn1" />
<%
ResultSet rs=null;
Connection conn = null;
NinGoo.setServer("127.0.0.1"); //设置MySQL的服务器名或者IP
NinGoo.setPort("3306"); //设置MySQL的监听端口
NinGoo.setDB("mysql"); //设置MySQL的数据库名
NinGoo.setUser("root"); //设置连接MySQL的用户名
NinGoo.setPass("sjjifk"); //设置连接MySQL的密码
conn = NinGoo.getConn() ;
rs= NinGoo.executeSQL("select * from help_topic");
rs.next();
%>
Row:<%=rs.getString(3)%>
<%rs.next();%>
<%out.print("Successful!\n");%>
<%
rs.close();
conn.close();
%>
</body>
</html>
解决方案 »
- jquery 的$.post()方法不执行回调函数
- java在下载带dtd的xml文件时会不会影响下载速度?
- struts2求助
- 请教:如何将jsp页面的存入的数据生成xml文件
- frame中 成功登陆 如何 跳转页面(struts)
- jstl标签无法正常显示
- 请问 http://mag.51fashion.net/10/Ray_0410/ 这个网站的图片浏览功能是怎么做出来的??
- 在servlet里能让一个窗口弹出来吗?
- SSH整合从数据库获取用户名跟密码的登陆时候出错
- 关于java的excel导入,为何有的实现先将文件先上传到工程的根目录下
- 数据库连接池的错误-来者有份-急!!!!就一个字
- PageContext的问题-困惑中
import java.sql.*;
public class dbconn1 {
public dbconn1() {
}
//declare variable
private Connection conn = null;
ResultSet rs = null;
private String server = "127.0.0.1";
private String port = "3306";
private String db = "test";
private String user = "root";
private String pass = "pass";
private String drivername="com.mysql.jdbc.Driver";
private String URL="jdbc:mysql://"+server+":"+port+"/"+db+"?user="+user+"&password="+pass; public Connection getConn(){//get database connection
try{
Class.forName("com.mysql.jdbc.Driver");
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
conn = DriverManager.getConnection(URL);
}
catch(Exception e){
e.printStackTrace();
}
return this.conn ;
} public void setServer(String str) {//set server name
this.server=str;
} public void setPort(String str) {//set server port
this.port = str;
} public void setDB(String str) {//set db name
this.db = str;
} public void setUser(String str) {//set user name
this.user = str;
} public void setPass(String str) {//set user name
this.pass = str;
} public ResultSet executeSQL(String str) {
try{
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(str);
}
catch(Exception e){
e.printStackTrace();
}
return this.rs;
}
}
Rs.getXXX(indexOF) 从第一行 rs.getString(1) 读还是不行呀
你的URL已经先生成了,后面传进去的参数不起作用了,改一下
public Connection getConn(){//get database connection
try{
URL="jdbc:mysql://"+server+":"+port+"/"+db+"?user="+user+"&password="+pass;
Class.forName("com.mysql.jdbc.Driver");
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
conn = DriverManager.getConnection(URL);
}
catch(Exception e){
e.printStackTrace();
}
return this.conn ;
}
private URL="jdbc:mysql://"+server+":"+port+"/"+db+"?user="+user+"&password="+pass;生成了,在 conn = DriverManager.getConnection(URL); 调用时候怎么不行了
呀
搞不明白。都引用参数。
为什么要写在方法里。
不是jdbs驱动的问题,是提示找不到驱动类的。
在你的JSP中调用SET方法的时候URL已经在内存中分配了一个空间,并且已经赋值了,所以在你调用getCon()的方法的时候并没有将你set的变量赋于URL
private String URL="jdbc:mysql://"+server+":"+port+"/"+db+"?user="+user+"&password="+pass;
当我调用set的方法时,url里的变理也在变成我方法给的值,
怎么在调用getconn方法 不能起做用呀在你的JSP中调用SET方法的时候URL已经在内存中分配了一个空间,并且已经赋值了,所以在你调用getCon()的方法的时候并没有将你set的变量赋于URL private 类型可以类被方问
url已结new 出来,怎么在getconn调用不起作用。 迷或
搞明白了 文稿哥们