Configuring web host mysql database in jsp website made in Netbeans -
i have made jsp website in netbeans tried , tested on local server through tomcat(using access database) , worked fine. web host has provided me host, database name, username , password of database. want configure website use database. don't know how that. have seen system.properties file in web-inf/config folder content this:
jndi_name=java:com/env/oracle/jndi db.login= db.password= driver=sun.jdbc.odbc.jdbcodbcdriver url=jdbc:odbc:mydb duser= dpass= logfile=log/aoc_log.txt dbname=my_db
but confused how modify file. also, database accessible web host.
below code shows how connection made (i think so...)
public connection getconnection() { try { if(con==null) { try { properties p = getproperties(); class.forname(p.getproperty("driver")); system.out.println("driver loaded"); con = drivermanager.getconnection(p.getproperty("url"),p.getproperty("duser"),p.getproperty("dpass")); system.out.println("connection established"); } catch (classnotfoundexception cnf) { loggermanager.writelogwarning(cnf); } } } catch (sqlexception sqlex) { sqlex.printstacktrace(); loggermanager.writelogsevere(sqlex); } return con; }
i figured out. in java code above function "getproperties()" fetch 'system.properties' file "web-inf/config" folder. can noticed in 'system.properties' file driver used making odbc connection. mine mysql database , hence have replace driver 'com.mysql.jdbc.driver'. url changed 'jdbc:mysql://192.168.0.1:3306/' 192.168.0.1 host , 3306 port. add database name in dbname field, username in duser field , password in dpass field. save , redeploy project , gets connected.
Comments
Post a Comment