File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Loading a file from disk into Oracle! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Loading a file from disk into Oracle!" Watch "Loading a file from disk into Oracle!" New topic
Author

Loading a file from disk into Oracle!

Raymond O'Leary
Greenhorn

Joined: Mar 23, 2004
Posts: 24
Hey guys,
What I'm trying to do here is load a text file from my g drive into oracle. I set up a connection the usual way and the statement @g:/stno.sql works perfectly if you type it directly into oracle!
Any clues why its not working?
Spare change?
Regards,
Ray
Here's my code by the way:
<%@ page language ="java" import="java.sql.*,oracle.jdbc.*" %>
<html>
<body>
<p>
<br><font color=midnightblue>
<h3>Start The Year</h3>
<p>
Click on the button to load student and supervisor tables into the database
<form name="startyear" method="post">
<p align="center"><input type="submit" value="Start Year" name="B2"></p>
<%
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc racle:thin:@witnt07.wit.ie:1521 rawit","29CSD03", "29CSD03");
Statement st=con.createStatement();
String strSQL = "@g:/stno.sql";
st.executeQuery(strSQL);
}
catch(Exception e1)
{}
%>
</form>
</body>
</html>
</font>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61612
    
  67

Perhaps you could define "not working"?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Raymond O'Leary
Greenhorn

Joined: Mar 23, 2004
Posts: 24
Bear,
when i click the button nothing happens. If i check the database the file i'm trying to insert isn't inserted.
Raymond
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
A couple of suggestions:
put a stack trace in your catch block

Stack trace might give us some insight into why it's not working.
And ideally you want to close your Connection at some point.
A good rule of thumb is to do the following:

And also, getting into this level of detail of java code in a jsp is usualy frowned upon, it should at least be put into a helper class/bean which can be used by the jsp.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61612
    
  67


Ewwww, I missed that. Good catch James.
This particular little idiom should never ever ever appear in your code!
Raymond O'Leary
Greenhorn

Joined: Mar 23, 2004
Posts: 24
Hey there,
I tried putting that printStackTrace in but JBuilder keeps telling me that the variable con1 cannot be found. I have it highlighted where and where not it cannot be found.
Help?
Spare Change?
Code:
<%
try{
Connection con1=null;
Class.forName("oracle.jdbc.driver.OracleDriver");
con1=DriverManager.getConnection("jdbc racle:thin:@witnt07.wit.ie:1521 rawit","29CSD03", "29CSD03");
Statement st=con1.createStatement();
String strSQL = "@g:/stno.sql";
st.executeQuery(strSQL);
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
if(con1 != null)//HERE****************************
{
try
{
con1.close();//OR HERE*************************
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
%>
</form>
</body>
</html>
</font>
Thanks guys
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
Move the declaration of your con1 variable outside of the try block:
Raymond O'Leary
Greenhorn

Joined: Mar 23, 2004
Posts: 24
Ah cheers.
The error I'm getting is an Invalid SQL Statement.
But if I type that exact statement into oracle it works perfectly.
I'll probably try take this to an SQL/Oracle forum if nobody else has any ideas?
Thanks for the help guys
Ray
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loading a file from disk into Oracle!