java.sql.SQLException: ORA-00942: table or view does not exist - java

when i was trying to read data from Oracle database using the following code i was getting exception
PreparedStatement pst=con.prepareStatement("SELECT * FROM TBLUSER");
pst.executeQuery();
But this table is actually exist in my database when i use this command directly in the command prompt its working fine.And also for one table among the tables in database this code is working fine ,but for other table names its not working properly.So someone please explain why this is happening.
java.sql.SQLException: ORA-00942: table or view does not exist
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:799)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1038)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:839)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1133)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3329)
at com.symp.ControllerServlet.service(ControllerServlet.java:302)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

Check each of the following:
1) the spelling of the table or view name.
2) that a view is not specified where a table is required.
3) that an existing table or view name exists.
Contact the database administrator if the table needs to be created or if user or application privileges are required to access the table.

Check if you are using the correcte informations :
String url = "jdbc:mysql://localhost:3306/YOUR_SCHEMA";
Driver driver = com.mysql.jdbc.Driver();
String userName = "user";
String password = "pass";

the problem is i am using multiple connections in the program to login to application i have used Oracle connection which is given as class level variable.And the client will be accessed his tables present in MySQL database using MySQL connection which is service method level variable.By mistakenly i have referred oracle connection variable and tried to acess mysql table

I had this error when using persist() in Hibernate and the solution was to execute:
grant all on <schema>.<table> to <user>;
grant all on <schema>.<sequence> to <user>;

Related

Java Servlet fails to connect to MySQL [duplicate]

This question already has answers here:
How to install JDBC driver in Eclipse web project without facing java.lang.ClassNotFoundexception
(13 answers)
Closed 6 years ago.
My code in java servlet is:
Class.forName("com.mysql.jdbc.Driver");
Connection connectionToSql = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/table_name", "root", "root");
PreparedStatement ask = connectionToSql.prepareStatement("SELECT COUNT(*) FROM table_name");
ResultSet result = ask.executeQuery();
But it throws exception e and the System.out.println(e.getMessage()); prints com.mysql.jdbc.Driver. The same code works in a standard java class, but fails in servlet. I can't find out where is the problem? help please.
Here is the full error message..
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
quiz.QuestionsPreparer.prepareQuestions(QuestionsPreparer.java:81)
quiz.QuestionsPreparer.doPost(QuestionsPreparer.java:42)
quiz.QuestionsPreparer.doGet(QuestionsPreparer.java:36)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
Without taking the look at your project folder structure and code, it is difficult to give you a solution.
But Below Statement from the link gives you the importance of Web Application folder structure.
https://tomcat.apache.org/tomcat-5.5-doc/appdev/deployment.html
/WEB-INF/classes/ - This directory contains Java class files from your application.
/WEB-INF/lib/ - This directory contains JAR files that contain Java class files (and associated resources) required for your application, such as third party class libraries or JDBC drivers.
you can unzip the war file and take a loot at the WEB_INF/lib for mysql jar files.
You can Do this way:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
Connection conn = null;
...
try {
conn =
DriverManager.getConnection("jdbc:mysql://localhost/test?" +
"user=minty&password=greatsqldb");
// Do something with the Connection
...
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}

JSP - Microsoft ODBC - Microsoft Access Driver Could not find file '(unknown)'

I am new to JSP. So i want to make a login web, but I stuck with the sql exception. Annyone know how to solve this? All program i use is 32bit, and I already add Ms Access Database to my user data sources.
here is the error information :
5: <%
6: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
7: Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="+application.getRealPath("WEB-INF/db.accdb"));
8: Statement st = con.createStatement(1004,1008);
9:
10: %>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
root cause
javax.servlet.ServletException: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845)
org.apache.jsp.khema.doLogin_jsp._jspService(doLogin_jsp.java:145)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
root cause
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'.
sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3073)
sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
java.sql.DriverManager.getConnection(DriverManager.java:582)
java.sql.DriverManager.getConnection(DriverManager.java:207)
org.apache.jsp.khema.doLogin_jsp._jspService(doLogin_jsp.java:72)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
For a start make sure that you specified the correct path to the DB file, once you do that do the following steps.
from the Control panel search for Administrative tools then search for Data Sources(ODBC) after that Add Microsoft Access Drivers(*mdb,*accdb).

Freemarker StringTemplateLoader

I am trying to load some Freemarker templating from the DB using stringLoader and executing them through template.process, but here is the problem, freemarker stuff like <#if... is executing but when I try to execute assign JspTaglibs it breaks.
Here is a simple example:
From the DB I get <#assign bean=JspTaglibs["/WEB-INF/struts-bean.tld]>, which i put in a in StringTemplateLoader. I create configuration, template.. so far everything is working. When I do template.process(data, out), the page reports:
Starting output:FreeMarker template error: The following has evaluated to null or missing: ==> JspTaglibs [in template "temp" at line 1, column 15] Tip: If the failing expression is known to be legally null/missing, either specify a default value with myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthessis: (myOptionVar.foo)!myDefault, (myOptionVar.foo)?? The failing instruction (FTL stack trace): ---------- ==> #assign bean = JspTaglibs["/WEB-INF/s... [in template "temp" at line 1, column 1] ---------- Java stack trace (for programmers): ---------- freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...] at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:98) at freemarker.core.DynamicKeyName._eval(DynamicKeyName.java:87) at freemarker.core.Expression.eval(Expression.java:111) at freemarker.core.Assignment.accept(Assignment.java:106) at freemarker.core.Environment.visit(Environment.java:265) at freemarker.core.Environment.process(Environment.java:243) at freemarker.template.Template.process(Template.java:277) at org.apache.jsp.test5_jsp._jspService(test5_jsp.java:109) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2440) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2429) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source)
Scenario that I have is that I have some code stored in the database and I would like to execute it by freemarker during template.process().
Is that even possible, and if it is, what am I doing wrong?
The problem is that JspTaglibs is not a core FreeMarker feature, but something that the FreemarkerServlet puts into the data-model, and something that requires Servlet environment and a HTTP request (as JSP requires that). Out of the box, there's no way to separate this feature from the FreemarkerServlet. However, maybe you can extend it so that you can still use it for your purpose. Most of the magic happens inside createModel, where among others, it adds JspTaglibs to the data-model.
It might also useful to know that FreeMarker (and thus FreemarkerServlet) can load templates directly from the database, if you give it a such TemplateLoader implementation through the FreeMarker Configuration. If all you want is serving templates from the database instead of where Struts traditionally stores them, you just need to provide the proper TemplateLoader.

Axis 2 WebService : wrong number of arguments when invoking method

I'm trying to set up a webservice using axis2.
I've created a Dynamic Web Projet under Eclipse, using Apache Tomcat 7 and the dynamic web version 2.5. I've added the Axis 2 Facets to the configuration.
I have the following class :
package com.jo.ws;
public class Test {
public int add(int a, int b) {
return a + b;
}
}
I then created a WebService for the projet, using the Bottom up Java bean Web Service, and adding my Test class to the service implementation.
I chose the "Start Service" in the slider, and changed Apache Axis in the configuration to Axis 2. I then generated a default services.xml file using the default option.
I can access my projet on the web at the following adress :
http://localhost:8888/Axis2WS/
This displays the Axis 2 page, and I can see my service is active
http://localhost:8888/Axis2WS/services/listServices
The wsdl is correctly generated and displayed
I can post it if needed.
But now if I do this :
http://localhost:8888/Axis2WS/services/Test?method=add&a=2&b=1
I get this :
<soapenv:Reason xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Text xml:lang="en-US">wrong number of arguments</soapenv:Text>
</soapenv:Reason>
I also got the error in my Eclipse console log, with the following stack trace :
[ERROR] wrong number of arguments
java.lang.IllegalArgumentException: wrong number of arguments
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:178)
at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.ja va:117)
at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMe ssageReceiver.java:40)
at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114 )
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
at org.apache.axis2.transport.http.util.RESTUtil.invokeAxisEngine(RESTUtil.java:144)
at org.apache.axis2.transport.http.util.RESTUtil.processURLRequest(RESTUtil.java:139)
at org.apache.axis2.transport.http.AxisServlet$RestRequestProcessor.processURLRequest(AxisServ let.java:837)
at org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:273)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.jav a:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java: 607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Any idea what I'm doing wrong ?
Thanks for your help !
The error came from the url I was typing in the browser..
The right url to invoke the method is :
http://localhost:8888/Axis2WS/services/Test/add?a=3&b=2
You need to replace the "?" with a "/" before the name of the method, and then write your parameters after you've added a "?" after the name of your method

java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: NO)

I'm having troubles with my project , it involves JDBC and Mysql connection .
When I do the following :
private Statement m_statement = null; // statement
private Connection m_connection = null; // connection
/**
* Constructor #1 of the Database class
* #throws ClassNotFoundException
*/
public Database() throws ClassNotFoundException
{
try
{
Class.forName("com.mysql.jdbc.Driver");
MysqlDataSource ds = new MysqlConnectionPoolDataSource();
ds.setServerName("localhost");
ds.setPort(3306);
ds.setUser("root");
ds.setPassword("");
this.m_connection = ds.getConnection();
this.m_statement = this.m_connection.createStatement();
}
catch (SQLException s)
{
System.out.println("SQL statement is not executed! 2!");
}
}
When I try to connect with the above code , the connection doesn't work ,here is the stacktrace :
java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: NO)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1244)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2397)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2430)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2215)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:813)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:334)
at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:443)
at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:141)
at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:111)
at db.Database.<init>(Database.java:99)
at controller.LoginPage.doGet(LoginPage.java:61)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
How can I fix it ?
Regards
I encounter the same error, this is how I fixed it:
I used DriverManager class like this:
Class.forName("com.mysql.jdbc.Driver");
Connection Hello = DriverManager.getConnection("jdbc:mysql://YOUR-URL-HERE", "USERNAME", "PASSWORD");
And that's it. Also, when selecting a table, remenber to put the DB name first, like:
"DB_NAME.TABLE_NAME".
TO check if mysql has a password, go to the directory where you installed mysql, and in the bin directory try to bring up mysql prompt using
./mysql –u root mysql
If the login goes through without any problem, it means no password is set.
You can use mysqadmin script to set/reset password.
./mysqladmin –u root password "password string"
Looks like you've only just installed mysql. Run mysql_secure_installation. It will prompt you for a root password, among other things.
I had the same problem. You need to set a password for the user. Go to the mysql console .
$ mysqladmin -u root password myFirstpassword
Then change your password in the java program
Either the username/password is wrong or the user is missing privileges to access the schema/table. Grant privileges using
GRANT ALL PRIVILEGES ON . TO 'root'#'localhost' WITH GRANT OPTION

Categories

Resources