java可以查询到mysql数据库的数据,jsp bean查询不到
我的java的代码,运行后输出okimportjava.util.*;importjava.net.*;importjava.sql.*;publicclassdbtes...
我的java的代码,运行后输出ok
import java.util.*;
import java.net.*;
import java.sql.*;
public class dbtest {
public dbtest() {
}
public Connection getCon() throws ClassNotFoundException, SQLException {
Connection con=null;
try {
Class.forName("com.mysql.jdbc.Driver");
String URL="jdbc:mysql://localhost:3306/dormitory?user=root&password=goodgoodstudy";
con=DriverManager.getConnection(URL);
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
public ResultSet DBQuery(String sqlText) {
Connection connl=null;
ResultSet rs=null;
try {
connl=getCon();
Statement stmt=connl.createStatement();
rs=stmt.executeQuery(sqlText);
} catch (Exception x) {
x.printStackTrace();
}
return rs;
}
public int DBUpdate(String sqlText) {
Connection connl=null;
int rowcount=0;
try {
connl=getCon();
Statement stmt=connl.createStatement();
rowcount=stmt.executeUpdate(sqlText);
} catch (Exception x) {
x.printStackTrace();
}
return rowcount;
}
public static void main(String[] args) {
dbtest myconnect = new dbtest();
String name="zhouqi";
String password="hello";
if (name!=null && password!=null) {
ResultSet rs;
String sqlText="select * from user where name= '"+name+"'and password='"+password+"';";
rs=myconnect.DBQuery(sqlText); 展开
import java.util.*;
import java.net.*;
import java.sql.*;
public class dbtest {
public dbtest() {
}
public Connection getCon() throws ClassNotFoundException, SQLException {
Connection con=null;
try {
Class.forName("com.mysql.jdbc.Driver");
String URL="jdbc:mysql://localhost:3306/dormitory?user=root&password=goodgoodstudy";
con=DriverManager.getConnection(URL);
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
public ResultSet DBQuery(String sqlText) {
Connection connl=null;
ResultSet rs=null;
try {
connl=getCon();
Statement stmt=connl.createStatement();
rs=stmt.executeQuery(sqlText);
} catch (Exception x) {
x.printStackTrace();
}
return rs;
}
public int DBUpdate(String sqlText) {
Connection connl=null;
int rowcount=0;
try {
connl=getCon();
Statement stmt=connl.createStatement();
rowcount=stmt.executeUpdate(sqlText);
} catch (Exception x) {
x.printStackTrace();
}
return rowcount;
}
public static void main(String[] args) {
dbtest myconnect = new dbtest();
String name="zhouqi";
String password="hello";
if (name!=null && password!=null) {
ResultSet rs;
String sqlText="select * from user where name= '"+name+"'and password='"+password+"';";
rs=myconnect.DBQuery(sqlText); 展开
2个回答
2013-11-21
展开全部
要看具体的错误信息
2013-11-22
展开全部
看到这么一大片代码,头晕;你也不说具体什么错误,怎么给你解决呀
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询