Class.forName("org.gjt.mm.mysql.Driver");
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");
//接管数据库连接实例
boolean coding = true;
EncodingConnection codingConnection = new EncodingConnection(con, coding, "ISO-8859-1", "GBK");
//获得接管后的数据库连接实例,以后直接使用con已经是经过EncodingConnection重新包装过的实例
con = codingConnection.getConnection();
pstmt = con.prepareStatement("SELECT f3, f4 FROM tbl1 WHERE f1 = ? AND f2 = ?");
pstmt.setString(1, f1);
pstmt.setString(2, f2);
rs = pstmt.executeQuery();
String f3, f4;
while(rs.next()) {
f3 = rs.getString(1);
f4 = rs.getString(2);
}
}
finally {
//close resouces
...
}
试试这样来取得连接,来实现增删改查
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");
//接管数据库连接实例
boolean coding = true;
EncodingConnection codingConnection = new EncodingConnection(con, coding, "ISO-8859-1", "GBK");
//获得接管后的数据库连接实例,以后直接使用con已经是经过EncodingConnection重新包装过的实例
con = codingConnection.getConnection();
pstmt = con.prepareStatement("SELECT f3, f4 FROM tbl1 WHERE f1 = ? AND f2 = ?");
pstmt.setString(1, f1);
pstmt.setString(2, f2);
rs = pstmt.executeQuery();
String f3, f4;
while(rs.next()) {
f3 = rs.getString(1);
f4 = rs.getString(2);
}
}
finally {
//close resouces
...
}
试试这样来取得连接,来实现增删改查
解决方案 »
- Web Service Connection reset
- 这种写法到底算什么?算单态吗?我要怎么用呢????
- 是不是最新版的eclipse有BUG啊?
- 【讨论】eclipse下tomcat项目的work目录
- 登陆的时候 出的错 tomcat报错 在线等 急
- MyEclipse中JSTL的配置问题..高手帮解决下
- 如何写WebService
- 关于继承和覆盖的问题~~~~~~~
- javamail接收邮件疑难问题(望java望高手给于解答,高分相送)
- 如何把如何把用j2ee的deploytool配置好的project.ear移植到weblogic6.0上去?
- hibernate一对多映射
- 谁读过《JSF第一步--JSF+Spring+Hibernate+AJAX编程实践》,请提宝贵意见
在数据库中的话 去mysql.inc中把类型设置成GBK就行了
在VIEW的话 转码就行了
前者检查JSP或配置过滤器
后者重新配置MySql的编码,中文数据插入的话,不要用默认的编码格式