java - unknown database in jdbc -
i using jdbc , new it. keep getting runtime exception:
connecting psysical database... com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: unknown database 'kholofelodb' @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:57) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:525) @ com.mysql.jdbc.util.handlenewinstance(util.java:411) @ com.mysql.jdbc.util.getinstance(util.java:386) @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:1052) @ com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:3609) @ com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:3541) @ com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:943) @ com.mysql.jdbc.mysqlio.secureauth411(mysqlio.java:4113) @ com.mysql.jdbc.mysqlio.dohandshake(mysqlio.java:1308) @ com.mysql.jdbc.connectionimpl.coreconnect(connectionimpl.java:2336) @ com.mysql.jdbc.connectionimpl.connectonetryonly(connectionimpl.java:2369) @ com.mysql.jdbc.connectionimpl.createnewio(connectionimpl.java:2153) @ com.mysql.jdbc.connectionimpl.<init>(connectionimpl.java:792) @ com.mysql.jdbc.jdbc4connection.<init>(jdbc4connection.java:47) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:57) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:525) @ com.mysql.jdbc.util.handlenewinstance(util.java:411) @ com.mysql.jdbc.connectionimpl.getinstance(connectionimpl.java:381) @ com.mysql.jdbc.nonregisteringdriver.connect(nonregisteringdriver.java:305) @ java.sql.drivermanager.getconnection(drivermanager.java:579) @ java.sql.drivermanager.getconnection(drivermanager.java:221) @ com.psybergate.database.simblecode.main(simblecode.java:22)
here gave code
try { string connectionurl = "jdbc:mysql://localhost:3306/kholofelodb"; class.forname("com.mysql.jdbc.driver"); system.out.println("connecting psysical database..."); connection conn = drivermanager.getconnection(connectionurl, user, pass); statement statement = conn.createstatement(); system.out.println("connection has been made"); scanner keyboardscanner = new scanner(system.in); system.out.println("enter table name:"); string tablename = keyboardscanner.nextline(); system.out.println("creating table..."); statement.executequery("create table " + tablename + " (name , age ,salary)"); system.out.println("table created"); system.out.println("inserting data table ..."); statement.executeupdate("insert " + tablename + "values (kholofelo , 21 , 9969696)"); }
how code work? beginner jdbc....
for above code; pass = "passowrd", user = "root"
i had problem port fixed through site
thanks lot
please check in mysql database whether database name 'kholofedb' existed or not
i think haven't created
please check once if no create , related tables
Comments
Post a Comment