Javabean connected to MySQL

xiaoxiao2021-03-06  62

package mysql; import java.sql *;. public class MySqlCon {private String DbName = ""; private String pass = ""; private String url = ""; private Connection con = null; private Statement stmt = null; private ResultSet rs = null; public MySqlCon () {} public void setDbName (String name) {this.DbName = name;} public void setPass (String pass) {this.pass = pass;} public void BulidCon () {try {Class.forName ("org.gjt.mm.mysql.driver"). Newinstance (); url = "jdbc: mysql: // localhost /" dbname "? user = root & password =" pass "& useunicode = true & characterencoding = GB2312"; con = DriverManager.getConnection (url); stmt = con.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);} catch (Exception e) {}} public ResultSet selectLog (String sql) {try {BulidCon (); rs = stmt. ExecuteQuery (SQL);} catch (eXception e) {system.out.println (e.tostring ());} return}} public void Updatelog (STRING SQL) {Try {BulidCon (); stmt.executeUpdate (SQL) ;} catch (exception e) {}} public void clos e () {Try {Con. close (); stmt.close ();} catch (sqlexception e) {}}}

More resources: Participate in the Forum Discussion: http://www.java-cn.com/index.jsp More Technical Articles: http://www.java-cn.com/technology/index.jspjava Chinese Station: We have to do China's best Java portal, remember our domain name: java-cn.com | java-cn.Net | java-cn.org this website URL: http://www.java-cn.com/technology /technology_detail.jsp?id=2914 Sound: Reprinted this article, you must indicate the original website of Java Chinese Station in a prominent location; if it is the reprinted article of this site, please indicate the original text, and retain the author information

转载请注明原文地址:https://www.9cbs.com/read-112392.html

New Post(0)