This article describes the method of jdbc operating mysql database. Share it for your reference. The details are as follows:
import .*; import ; import ; import ; import ; class conn{ String url="jdbc:mysql://127.0.0.1/nariData"; final String user = "nari"; final String pass = "nariacc"; Connection conn = null; Statement st = null; ResultSet rs = null; conn(){ try{ (""); }catch(Exception e){ (); } try{ ("in DBManager"); conn = (url, user, pass); String sql = "create table test (id int, uid int)"; st = (); (sql); }catch(Exception e){ (); } } void insert(){ try{ for(int i=0;i<10;i++){ String sql = "insert into test values("+i+","+i+")"; (sql); } }catch(Exception e){ (); } } void query(){ try{ String sql = "select * from test "; rs = (sql); while(()){ ("res1: "+(1)+" res2: "+(2)+"\n"); } }catch(Exception e){ (); } } void close(){ try{ (); (); (); }catch(Exception e){ (); } } } public class mysqltest { public static void main(String[] args) { // TODO Auto-generated method stub conn a1 = new conn(); (); (); (); } }
I hope this article will be helpful to everyone's JSP programming.