Issues with derby Database using a GUI - user-interface

I am asking this question because I was unable to find a similar question. I recently completed this college project where I made a console application that connected to the database and everything seemed perfectly fine. The method I used to connect to the database is this:
private static Connection getConnection()
{
Connection connection = null;
try
{
String dbDirectory = "c:/murach/java/db";
System.setProperty("derby.system.home", dbDirectory);
String dbURL = "jdbc:derby:MurachDB2";
String username = "";
String password = "";
connection = DriverManager.getConnection(dbURL, username, password);
System.out.println("connect works");
return connection;
} //end try connection statement
catch (SQLException e)
{
for (Throwable t : e)
{
e.printStackTrace();
System.out.println("something went wrong on connection method");
} //end for loop for errors
} // end catch statement for connection error
return connection;
}
As I said before I created the console application and everything seemed fine and I turned it in. However, I wanted to experiment with something, I wanted to make another version of this application but instead a GUI application using Jform. I used all of the same classes as before, except that instead of a main class, I used a jform. The method and class is exactly the same, because the database didn't change locations in my folder, however when I run it in the Jform application I get a runtime error.
What it was a null point error and I knew it had something to do with connecting to the database because I wrote a System.out.Println in the catch SQL Exception to notify that something went wrong with the method. The connect to the database is fine with the console application, but my question is if there is any further measures I need to take when it comes to working with a JFrame application. Is there anything I am missing or is there any extra step I need to do. For further measures I will display the whole class that works with the database, and I will also use the event handlers in the Jframe.
I want to make this clear in which that I am not required to do this. I am just playing around with Java, and I could easily leave this alone without consequences, but I feel I really want to learn this so this is why I am asking for help. Any kind of advice or if any of you can let you know what I am missing I would really appreciate it.
Edit
adding error information
>java.sql.SQLException: No suitable driver found for jdbc:derby:MurachDB2
something went wrong on connection method
java.lang.NullPointerException
something went from with dislay part
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at CustomerInvoiceDB.getConnection(CustomerInvoiceDB.java:38)
at CustomerInvoiceDB.getCustomers(CustomerInvoiceDB.java:67)
at CutomerInvoice.displayButtonActionPerformed(CutomerInvoice.java:111)
at CutomerInvoice.access$000(CutomerInvoice.java:24)
at CutomerInvoice$1.actionPerformed(CutomerInvoice.java:57)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Related

ClassCastException trying to get OracleConnection from JdbcTemplate

I am creating an ArrayDescriptor in order to pass CLOB data to an Oracle function. I have a class in which I have injected (#Inject) a jdbcTemplate...this is an implementation class which has calls out to Oracle. I am creating the ArrayDescriptor like:
Connection conn = auditJdbcTemplate.getDataSource().getConnection();
ArrayDescriptor keyArryDesc = ArrayDescriptor.createDescriptor("VC_ARR", conn);
The error I am receiving is:
java.lang.ClassCastException: com.sun.proxy.$Proxy183 cannot be cast to oracle.jdbc.OracleConnection
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:105
As I stated, I have direct calls in this class to auditJdbcTemplate.update that work successfully so I am not sure why it can't return a valid connection object from the template. I have seen several answers in StackOverflow to get the underlying connection and I have not been able to get that to work.
Maybe someone find it useful:
Connection conn = jdbcTemplate.getDataSource().getConnection().unwrap(OracleConnection.class);

JT400.jar Disable Login Screen

Can anyone help me out? I have small utility application that uses the Jt400-6.7.jar to connect to an AS400 server.
Please see the following code
private Connection buildConnection(String url, String userName, String password) throws ClassNotFoundException,
SQLException {
Connection connection = null;
Class.forName("com.ibm.as400.access.AS400JDBCDriver");
DriverManager.setLoginTimeout(10000);
//OVER HERE!!!
connection = DriverManager.getConnection(url, userName, password);
return connection;
}
The code above works but if the the username or the password is wrong the application creates the following login screen. It happens when DriverManager.getConnection() is executed.
Cant post a picture but it looks something like this
Signon to the system X
System: AS400Server
User ID: User ID
Password: ********
O Default User ID
O Save Password
OK Cancel
Can anyone tell me how to disable this feature??
One way to disable this feature is to set the JVM property, com.ibm.as400.access.AS400.guiAvailable=false.
From a java command line, you would set this using java -Dcom.ibm.as400.access.AS400.guiAvailable=false ...
Here is an example using the jdbc client included in jt400.jar
C:\>java -cp jt400.jar -Dcom.ibm.as400.access.AS400.guiAvailable=false com.ibm.as400.access.jdbcClient.Main jdbc:as400:/SYSTEM
Warning: Unable to connect to jdbc:as400:/SYSTEM using null
CON is not defined
The second way to disable this feature is to use the prompt=false connection property. For example.
C:\jtopen_build\dist6>java -cp jt400.jar com.ibm.as400.access.jdbcClient.Main jdbc:as400:/SYSTEM;prompt=false
Warning: Unable to connect to jdbc:as400:/SYSTEM;prompt=false using null
CON is not defined
Another method for preventing the GUI password prompt.
AS400.setPasswordExpirationWarningDays(-1);
Properties properties = new Properties();
properties.put("extended metadata", "true");
properties.put("user", userProfile);
properties.put("password", password);
properties.put("driver", "native");
properties.put("prompt", "false");
DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
Connection connection = DriverManager.getConnection("jdbc:as400://somedomain.com", properties);
Just to add, when calling a RPG program from java, same Sign-on pop up arrives.You can turn it off by setting com.ibm.as400.access.AS400 object's setGuiAvailable(false);
You can also set it when defining the DataSource:
final AS400JDBCDataSource dataSourceISeries = new AS400JDBCDataSource();
dataSourceISeries.setDatabaseName(...);
dataSourceISeries.setUser(...);
...
dataSourceISeries.setPrompt(false);

Alfresco : Increase document version when overriding file in ftp

I want to increase minor document version when overriding file in ftp. When I traced the code, ContentDiskDriver2.truncateFile() works for overriding file. Inside this function I use versionService to increase version. Following code is written in truncateFile()
try {
NodeRef nodeRef = getNodeForPath(tree, DriverContent.FILE_OPEN_PARAMS.getPath());
System.out.println("Node Ref: " + nodeRef);
// Increase minor version to file.
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(2, 1.0f);
versionProperties.put(Version.PROP_DESCRIPTION, "");
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
VersionService versionService = (VersionService) applicationContext.getBean("versionService");
versionService.createVersion(nodeRef, versionProperties);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
But unfortunately I got this error.
2013-01-02 14:12:31,609 ERROR [org.alfresco.fileserver] [Sess_FTP3_192.168.1.166] Error from JLAN
org.alfresco.error.AlfrescoRuntimeException: 00020073 Transaction must be active and synchronization is required: Thread[Sess_FTP3_192.168.1.166,5,FTPSessions]
at org.alfresco.repo.transaction.AlfrescoTransactionSupport.registerSynchronizations(AlfrescoTransactionSupport.java:467)
at org.alfresco.repo.transaction.AlfrescoTransactionSupport.getSynchronization(AlfrescoTransactionSupport.java:451)
at org.alfresco.repo.transaction.AlfrescoTransactionSupport.getResource(AlfrescoTransactionSupport.java:244)
at org.alfresco.repo.transaction.TransactionalResourceHelper.incrementCount(TransactionalResourceHelper.java:71)
at org.alfresco.repo.policy.BehaviourFilterImpl.disableBehaviour(BehaviourFilterImpl.java:158)
at org.alfresco.repo.version.Version2ServiceImpl.createVersion(Version2ServiceImpl.java:212)
at org.alfresco.repo.version.Version2ServiceImpl.createVersion(Version2ServiceImpl.java:140)
at org.alfresco.filesys.repo.ContentDiskDriver2.increaseVersion(ContentDiskDriver2.java:2937)
at org.alfresco.filesys.repo.ContentDiskDriver2.truncateFile(ContentDiskDriver2.java:1652)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
at $Proxy97.truncateFile(Unknown Source)
at org.alfresco.filesys.repo.NonTransactionalRuleContentDiskDriver.truncateFile(NonTransactionalRuleContentDiskDriver.java:480)
at org.alfresco.filesys.repo.LegacyFileStateDriver.truncateFile(LegacyFileStateDriver.java:471)
at org.alfresco.filesys.repo.BufferedContentDiskDriver.truncateFile(BufferedContentDiskDriver.java:532)
at org.alfresco.jlan.ftp.FTPSrvSession.procStoreFile(FTPSrvSession.java:2262)
at org.alfresco.jlan.ftp.FTPSrvSession.run(FTPSrvSession.java:4924)
at java.lang.Thread.run(Thread.java:662)
Can you help me how to solve Transaction must be active and synchronization is required
I found this link..
Is the Alfresco repository document version history available via CIFS/FTP?
You've been caught by "little letter" vs "Big Letter" Alfresco services
"little letter" services are the raw services, and normally only used within other Alfresco low level services. "Big Letter" services are the wrapped user facing services, which include transactions, auditing, security etc.
For your case, you need to use the Big Letter form, so change the line
VersionService versionService = (VersionService) applicationContext.getBean("versionService");
To the correct one:
VersionService versionService = (VersionService) applicationContext.getBean("VersionService");
And you'll get a copy of the VersionService with transactions, security etc, which is what I think you need for your situation. (Note that the bean is fetched with a Big First Letter rather than little letter)
This is alternative solution I found. The use of transaction explicitly.
VersionService versionService = (VersionService) applicationContext.getBean("VersionService");
TransactionService transactionService = (TransactionService) applicationContext.getBean("transactionService");
UserTransaction tx = null;
try {
tx = transactionService.getUserTransaction();
tx.begin();
versionService.createVersion(nodeRef, versionProperties);
tx.commit();
}
catch (Exception e)
{
if(tx != null)
{
try
{
tx.rollback();
} catch (IllegalStateException e1)
{
e1.printStackTrace();
} catch (SecurityException e2)
{
e2.printStackTrace();
} catch (SystemException e3)
{
e3.printStackTrace();
}
}
}

Hive JDBC getConnection does not return

I'm following the hive JDBC tutorial. I could not get it working. When it try to get the connection it just hangs. It does not report any error either. I'm sure the Hive server is running. Any help?
public class HiveJdbcClient {
private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
public static void main(String[] args){
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.exit(1);
}
try{
Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/default", "", "");
System.out.println("got the connection");
}catch(SQLException e){
e.printStackTrace();
}
}
}
output of the netstat:
$ sudo netstat -anlp | grep 10000
Password:
tcp 0 0 0.0.0.0:10000 0.0.0.0:* LISTEN 27738/java
tcp 107 0 127.0.0.1:10000 127.0.0.1:45910 ESTABLISHED 27738/java
tcp 0 0 127.0.0.1:33665 127.0.0.1:10000 ESTABLISHED 24475/java
tcp 0 0 127.0.0.1:45910 127.0.0.1:10000 ESTABLISHED 7445/java
tcp 107 0 127.0.0.1:10000 127.0.0.1:33665 ESTABLISHED 27738/java
Naresh: Try stopping the triffserver, then move to the HIVE_HOME/bin directory from your terminal, then start the hive trift server using the ./hive --service hiveserver 10000 & command. Then try running the program. Do a create table as per the hive client wiki example . Then do a show tables query in the next step. Let us know the result once this steps are followed. We can have a discussion after that.
You can do the following to pinpoint where the hang is happening. Here is an example that I did to trace it in my broken Hive JDBC connection. Note that this is not a concrete solution to any generic hive connection hanging error.
This is an answer to the question: "how can I find out where my JDBC hive connection is hanging? "
What makes this hard to trace is the JDBC dynamic invocation. Instead, you can just manually createa HiveConnection() class. That allows you to add some tracing into the code directly, to see where the hang is happening.
I've traced this by doing the following.
* USING LOG4J *
The thrift and other JDBC hive classes use log4j when connecting, if you turn DEBUG logging on, you can see fine grained errors. You can do this easily by adding
BasicConfigurator.configure()
To your client app. In any case, doing this led me to find that this seems to be stalling in the SASL transport layer. I guess it could be security related but I would assume that a security error would STILL return, and not hang... So I think this may be worthy of a JIRA. I've pasted a follow up question:
How can I trace the failure ot TSaslTransport (hive related)
* ANOTHER METHOD *
1) You can grab a copy of the "HiveConnection" class from github, or wherever, and instantiate a new one:
String url=String.format("jdbc:hive2://%s:%s/default",
server,
port)
Properties p = new Properties();
p.setProperty("host", con);
Connection jdbc = new HiveConnection(url,p);
Then, you can add your debugger hooks or log statements to the HiveConnection() class.
Ulitmately, when i had this error, I traced it to:
openTransport
Which ultimately creates a
org.apache.thrift.transport.TSaslClientTransport
instance.
And the hang happens in this code block:
try {
System.out.println(".....1 carrying on... attempting to open. " + transport.getClass().getName());
transport.open();
System.out.println("done open.");
}
catch (TTransportException e) {
System.out.println("2 fail .");
e.printStackTrace();
throw new SQLException("Could not establish connection to "
+ uri + ": " + e.getMessage(), " 08S01");
}
FYI I've posted a follow up regarding why MY connection failed. It might be related to yours as well... How can I trace the failure ot TSaslTransport (hive related)
I had the same problem/ Check this params:
driverName = "org.apache.hive.jdbc.HiveDriver"
con = DriverManager.getConnection("jdbc:hive2://192.168.1.93:10000/default", "", "");

No data records returned from Oracle 10g DB using JSP

I have inserted the following java code in the body part of my jsp page to retrieve the records of the table FLIGHTDATA from a Oracle 10g database. But after the execution of the Class.forName(...) line the program directly goes to finally block and closing the connection without returning any data. Any suggestions on what I am doing wrong ? Thanks - Somnath
<%# page import="java.sql.*" %>
<%# page import="java.io.*" %>
<%
out.println("<table border='1'><tr>");
Connection connection = null;
Statement statement = null;
ResultSet rs_1hop = null;
ResultSetMetaData rsm_1hop = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String connectionURL = "jdbc:oracle:thin:#localhost:1521:xe";
connection = DriverManager.getConnection(connectionURL, "system", "system");
statement = connection.createStatement();
// sql query to retrieve values from the secified table.
String QueryString = "SELECT * from FLIGHTDATA";
rs_1hop = statement.executeQuery(QueryString);
rsm_1hop = rs_1hop.getMetaData();
int colCnt = rsm_1hop.getColumnCount();
for (int i=1; i<=colCnt; ++i) {
out.println("<th>" + rsm_1hop.getColumnName(i) + "</th>");
}
out.println("</tr>");
while (rs_1hop.next()) {
out.println("<tr>");
for (int i=1; i<=colCnt; ++i)
out.println("<td>" + rs_1hop.getString(i) + "</td>");
out.println("</tr>");
}
} catch (Exception e) {
} finally {
if (statement != null)
statement.close();
if (connection != null)
connection.close();
}
out.println("</table><br><br>");
%>
After adding the ServletException in the catch block as commented by BalusC, and adding the odbc6.jar files under /WEB-INF/lib, I am getting the following error message which I suppose is due to the jdbc driver not found.
I also tried adding the jar files under Apache Tomcat installation dir /ROOT/web-apps/WEB_INF/lib so that they are available for all web-apps but the problem persists.
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: javax.servlet.ServletException: DB interaction failed! org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:500)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
javax.servlet.ServletException: DB interaction failed!
org.apache.jsp.retrievePossibleRoutes_jsp._jspService(retrievePossibleRoutes_jsp.java:96)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:128)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
org.apache.jsp.retrievePossibleRoutes_jsp._jspService(retrievePossibleRoutes_jsp.java:73)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
But after the execution of the Class.forName(...) line the program directly goes to finally block
That can only happen if a ClassNotFoundException was been thrown. This means that concrete class as specified by the given class name is not in the webapp's runtime classpath at all. That class is part of the Oracle JDBC driver. Putting the Oracle JDBC driver JAR file in /WEB-INF/lib folder of the webapp should fix that problem.
Further I strongly recommend you to do something in that empty catch (Exception e) {} block to indicate that an exception has occurred. Right now you're stabbing clueless around in the dark as to what really happened. If you have rethrown it as a ServletException, then you'd have gotten a much more self-explaining error page instead of a halfbaked JSP result.
} catch (Exception e) {
throw new ServletException(e);
}
Last but not least, writing Java code in a JSP file is a bad practice. How to salvage this properly, check this answer: Show JDBC ResultSet in HTML in JSP page using MVC and DAO pattern.
Update as per your update:
After adding the ServletException in the catch block as commented by BalusC, and adding the odbc6.jar files under /WEB-INF/lib, I am getting the following error message which I suppose is due to the jdbc driver not found.
Then it's the wrong JAR file (i.e. it's not the one containing the oracle.jdbc.driver.OracleDriver class), or you didn't rebuild/redeploy/restart the webapp properly. Make sure that you've downloaded the right JDBC driver for your Oracle database version as listed here. Make sure that you've properly rebuilt/redeployed/restarted the webapp.
I also tried adding the jar files under Apache Tomcat installation dir /ROOT/web-apps/WEB_INF/lib so that they are available for all web-apps but the problem persists.
This is nonsense. Undo this change. To make a JAR available to all deployed webapps, put it in Tomcat's own /lib folder (the one straight in Tomcat installation folder). But that won't solve your problem if it's the wrong JAR file.

Resources