java - MySQL JDBC Web Program: error in DB config -


i trying simple select mysql database in java web project.

i have mysql , running on localhost. have database named "lab" , table named "lab_user" 1 record:

enter image description here enter image description here

the issue every time try select 1 row program, error saying table not exist. believe may doing wrong db config.

below can find code, web.xml , context.xml.

could please me find out if there wrong in here preventing me accessing correct database?

thank you

code

package dao;  import java.sql.*; import javax.naming.*; import javax.sql.*;  import dto.userdto;  public class userdao {      private connection connection = null;     private statement statement = null;     private preparedstatement prepstatement = null;     private resultset results = null;     private static final string datasource_name = "java:comp/env/jdbc/lab";       public void getconnection() {         if (connection == null) {             try {                 context initialcontext = new initialcontext();                 datasource ds = (datasource) initialcontext.lookup(datasource_name);                 connection = ds.getconnection();             } catch (namingexception e) {                 e.printstacktrace();             } catch (sqlexception e) {                 e.printstacktrace();             }         }     }      public userdto selectuser(string userid) {          //pessoal         string id = "";         string name = "";          try {             getconnection();             statement = connection.createstatement();             results = statement.executequery("select * lab_user user_id = 1");              if (results != null) {                 results.next();                  id = results.getstring("id");                 name = results.getstring("name");             }             results = null;             ///          } catch (sqlexception e) {              string error = "" + e;             e.printstacktrace();          } {             cleanup();          }         results = null;          userdto udto = new userdto();         udto.setname(name);         udto.setid(id);          return udto;     } 

web.xml

<description>db connection</description>   <res-ref-name>jdbc/lab</res-ref-name>   <res-type>javax.sql.datasource</res-type>   <res-auth>container</res-auth> 

context.xml

<context>   <resource auth="container" driverclassname="com.mysql.jdbc.driver" maxactive="30" maxidle="100" maxwait="10000" name="labdb" password="hacking" type="javax.sql.datasource" url="jdbc:mysql://localhost:3306/lab?zerodatetimebehavior=converttonull" username="fabio"/> </context> 

error: java.sql.sqlsyntaxerrorexception: table/view 'lab_user' not exist.

i don't see name attribute in context. should this:

<context>     <resource name="jdbc/lab" auth="container" driverclassname="com.mysql.jdbc.driver" maxactive="30" maxidle="100" maxwait="10000" name="labdb" password="hacking" type="javax.sql.datasource" url="jdbc:mysql://localhost:3306/lab?zerodatetimebehavior=converttonull" username="fabio"/> </context> 

otherwise application cannot access defined data source.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -