Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loading a file from disk into Oracle!

 
Raymond O'Leary
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65339
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you could define "not working"?
 
Raymond O'Leary
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65339
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ewwww, I missed that. Good catch James.
This particular little idiom should never ever ever appear in your code!
 
Raymond O'Leary
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Move the declaration of your con1 variable outside of the try block:
 
Raymond O'Leary
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic