Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

java.sql.SQLException: SQL string is not Query

[es] :: Java :: java.sql.SQLException: SQL string is not Query

[ Pregleda: 2766 | Odgovora: 10 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

infob

Član broj: 144678
Poruke: 34
91.191.15.*



Profil

icon java.sql.SQLException: SQL string is not Query24.10.2007. u 18:33 - pre 200 meseci
Na web aplikaciji, koju radim u JDeveloper-u, mi pri pokretanju fajla "Formatlist.jsp" browser pokaze ovu gresku:
"java.sql.SQLException: SQL string is not Query"

Konekcija treba da se iz ove stranice uspostavi na Oracle 10g XE.
Ako bi neko mogao da mi pomogne? Hvala unaprijed!
Kod fajlova: "Formatlist.jsp" i "db.jsp" sam postavio ispod.




"Formatlist.jsp"
Code:
<%@ page session="true" buffer="16kb" import="java.sql.*,java.util.*,java.text.*"%>
<%@ page import="oracle.jdbc.*" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<% Locale locale = Locale.getDefault();
response.setLocale(locale);%>
<% session.setMaxInactiveInterval(30*60); %>
<%@ include file="db.jsp" %>
<%@ include file="jspmkrfn.jsp" %>
<%
int displayRecs = 20;
int recRange = 10;
%>
<%
String tmpfld = null;
String escapeString = "''";
String dbwhere = "";
String masterdetailwhere = "";
String searchwhere = "";
String a_search = "";
String b_search = "";
String whereClause = "";
int startRec = 0, stopRec = 0, totalRecs = 0, recCount = 0;
%>
<%

// Get search criteria for basic search
String pSearch = request.getParameter("psearch");
String pSearchType = request.getParameter("psearchtype");
if (pSearch != null && pSearch.length() > 0) {
    pSearch = pSearch.replaceAll("'",escapeString);
    if (pSearchType != null && pSearchType.length() > 0) {
        while (pSearch.indexOf("  ") > 0) {
            pSearch = pSearch.replaceAll("  ", " ");
        }
        String [] arpSearch = pSearch.trim().split(" ");
        for (int i = 0; i < arpSearch.length; i++){
            String kw = arpSearch[i].trim();
            b_search = b_search + "(";
            b_search = b_search + "\"ID_F\" LIKE '%" + kw + "%' OR ";
            b_search = b_search + "\"Naziv_F\" LIKE '%" + kw + "%' OR ";
            if (b_search.substring(b_search.length()-4,b_search.length()).equals(" OR ")) { b_search = b_search.substring(0,b_search.length()-4);}
            b_search = b_search + ") " + pSearchType + " ";
        }
    }else{
        b_search = b_search + "\"ID_F\" LIKE '%" + pSearch + "%' OR ";
        b_search = b_search + "\"Naziv_F\" LIKE '%" + pSearch + "%' OR ";
    }
}
if (b_search.length() > 4 && b_search.substring(b_search.length()-4,b_search.length()).equals(" OR ")) {b_search = b_search.substring(0, b_search.length()-4);}
if (b_search.length() > 5 && b_search.substring(b_search.length()-5,b_search.length()).equals(" AND ")) {b_search = b_search.substring(0, b_search.length()-5);}
%>
<%

// Build search criteria
if (a_search != null && a_search.length() > 0) {
    searchwhere = a_search; // Advanced search
}else if (b_search != null && b_search.length() > 0) {
    searchwhere = b_search; // Basic search
}

// Save search criteria
if (searchwhere != null && searchwhere.length() > 0) {
    session.setAttribute("Format_searchwhere", searchwhere);
    startRec = 1; // Reset start record counter (new search)
    session.setAttribute("Format_REC", new Integer(startRec));
}else{
    if (session.getAttribute("Format_searchwhere") != null)
        searchwhere = (String) session.getAttribute("Format_searchwhere");
}
%>
<%

// Get clear search cmd
startRec = 0;
if (request.getParameter("cmd") != null && request.getParameter("cmd").length() > 0) {
    String cmd = request.getParameter("cmd");
    if (cmd.toUpperCase().equals("RESET")) {
        searchwhere = ""; // Reset search criteria
        session.setAttribute("Format_searchwhere", searchwhere);
    }else if (cmd.toUpperCase().equals("RESETALL")) {
        searchwhere = ""; // Reset search criteria
        session.setAttribute("Format_searchwhere", searchwhere);
    }
    startRec = 1; // Reset start record counter (reset command)
    session.setAttribute("Format_REC", new Integer(startRec));
}

// Build dbwhere
if (masterdetailwhere != null && masterdetailwhere.length() > 0) {
    dbwhere = dbwhere + "(" + masterdetailwhere + ") AND ";
}
if (searchwhere != null && searchwhere.length() > 0) {
    dbwhere = dbwhere + "(" + searchwhere + ") AND ";
}
if (dbwhere != null && dbwhere.length() > 5) {
    dbwhere = dbwhere.substring(0, dbwhere.length()-5); // Trim rightmost AND
}
%>
<%

// Load Default Order
String DefaultOrder = "";
String DefaultOrderType = "";

// No Default Filter
String DefaultFilter = "";

// Check for an Order parameter
String OrderBy = request.getParameter("order");
if (OrderBy != null && OrderBy.length() > 0) {
    if (session.getAttribute("Format_OB") != null &&
        ((String) session.getAttribute("Format_OB")).equals(OrderBy)) { // Check if an ASC/DESC toggle is required
        if (((String) session.getAttribute("Format_OT")).equals("ASC")) {
            session.setAttribute("Format_OT", "DESC");
        }else{
            session.setAttribute("Format_OT", "ASC");
        }
    }else{
        session.setAttribute("Format_OT", "ASC");
    }
    session.setAttribute("Format_OB", OrderBy);
    session.setAttribute("Format_REC", new Integer(1));
}else{
    OrderBy = (String) session.getAttribute("Format_OB");
    if (OrderBy == null || OrderBy.length() == 0) {
        OrderBy = DefaultOrder;
        session.setAttribute("Format_OB", OrderBy);
        session.setAttribute("Format_OT", DefaultOrderType);
    }
}

// Open Connection to the database
try{
Statement stmt = (Statement) conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
stmt.executeQuery("ALTER SESSION SET CURRENT_SCHEMA = NIKOLA");
ResultSet rs = null;

// Build SQL
String strsql = "SELECT * FROM \"Format\"";
whereClause = "";
if (DefaultFilter.length() > 0) {
    whereClause = whereClause + "(" + DefaultFilter + ") AND ";
}
if (dbwhere.length() > 0) {
    whereClause = whereClause + "(" + dbwhere + ") AND ";
}
if (whereClause.length() > 5 && whereClause.substring(whereClause.length()-5, whereClause.length()).equals(" AND ")) {
    whereClause = whereClause.substring(0, whereClause.length()-5);
}
if (whereClause.length() > 0) {
    strsql = strsql + " WHERE " + whereClause;
}
if (OrderBy != null && OrderBy.length() > 0) {
    strsql = strsql + " ORDER BY \"" + OrderBy + "\" " + (String) session.getAttribute("Format_OT");
}

//out.println(strsql);
rs = (ResultSet) stmt.executeQuery(strsql);
rs.last();
totalRecs = rs.getRow();
rs.beforeFirst();
startRec = 0;
int pageno = 0;

// Check for a START parameter
if (request.getParameter("start") != null && Integer.parseInt(request.getParameter("start")) > 0) {
    startRec = Integer.parseInt(request.getParameter("start"));
    session.setAttribute("Format_REC", new Integer(startRec));
}else if (request.getParameter("pageno") != null && Integer.parseInt(request.getParameter("pageno")) > 0) {
    pageno = Integer.parseInt(request.getParameter("pageno"));
    if (IsNumeric(request.getParameter("pageno"))) {
        startRec = (pageno-1)*displayRecs+1;
        if (startRec <= 0) {
            startRec = 1;
        }else if (startRec >= ((totalRecs-1)/displayRecs)*displayRecs+1) {
            startRec =  ((totalRecs-1)/displayRecs)*displayRecs+1;
        }
        session.setAttribute("Format_REC", new Integer(startRec));
    }else {
        startRec = ((Integer) session.getAttribute("Format_REC")).intValue();
        if (startRec <= 0) {
            startRec = 1; // Reset start record counter
            session.setAttribute("Format_REC", new Integer(startRec));
        }
    }
}else{
    if (session.getAttribute("Format_REC") != null)
        startRec = ((Integer) session.getAttribute("Format_REC")).intValue();
    if (startRec==0) {
        startRec = 1; //Reset start record counter
        session.setAttribute("Format_REC", new Integer(startRec));
    }
}
%>
<%@ include file="header.jsp" %>
<p><span class="jspmaker">TABLE: Format</span></p>
<form action="Formatlist.jsp">
<table border="0" cellspacing="0" cellpadding="4">
    <tr>
        <td><span class="jspmaker">Quick Search (*)</span></td>
        <td><span class="jspmaker">
            <input type="text" name="psearch" size="20">
            <input type="Submit" name="Submit" value="GO">
        &nbsp;&nbsp;<a href="Formatlist.jsp?cmd=reset">Show all</a>
        </span></td>
    </tr>
    <tr><td>&nbsp;</td><td><span class="jspmaker"><input type="radio" name="psearchtype" value="" checked>Exact phrase&nbsp;&nbsp;<input type="radio" name="psearchtype" value="AND">All words&nbsp;&nbsp;<input type="radio" name="psearchtype" value="OR">Any word</span></td></tr>
</table>
</form>
<form method="post">
<table border="0" cellspacing="2" cellpadding="4" bgcolor="#CCCCCC">
    <tr bgcolor="#FF3300">
        <td><span class="jspmaker" style="color: #FFFFFF;">
<a href="Formatlist.jsp?order=<%= java.net.URLEncoder.encode("ID_F","UTF-8") %>" style="color: #FFFFFF;">ID F&nbsp;(*)<% if (OrderBy != null && OrderBy.equals("ID_F")) { %><span class="ewTableOrderIndicator"><% if (((String) session.getAttribute("Format_OT")).equals("ASC")) {%>5<% }else if (((String) session.getAttribute("Format_OT")).equals("DESC")) { %>6<% } %></span><% } %></a>
        </span></td>
        <td><span class="jspmaker" style="color: #FFFFFF;">
<a href="Formatlist.jsp?order=<%= java.net.URLEncoder.encode("Naziv_F","UTF-8") %>" style="color: #FFFFFF;">Naziv F&nbsp;(*)<% if (OrderBy != null && OrderBy.equals("Naziv_F")) { %><span class="ewTableOrderIndicator"><% if (((String) session.getAttribute("Format_OT")).equals("ASC")) {%>5<% }else if (((String) session.getAttribute("Format_OT")).equals("DESC")) { %>6<% } %></span><% } %></a>
        </span></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<%

// Avoid starting record > total records
if (startRec > totalRecs) {
    startRec = totalRecs;
}

// Set the last record to display
stopRec = startRec + displayRecs - 1;

// Move to first record directly for performance reason
recCount = startRec - 1;
if (rs.next()) {
    rs.first();
    rs.relative(startRec - 1);
}
long recActual = 0;
if (startRec == 1)
   rs.beforeFirst();
else
   rs.previous();
while (rs.next() && recCount < stopRec) {
    recCount++;
    if (recCount >= startRec) {
        recActual++;
%>
<%
    String bgcolor = "#FFFFFF"; // Set row color
%>
<%
    if (recCount%2 != 0) { // Display alternate color for rows
        bgcolor = "#F5F5F5";
    }
%>
<%
    String x_ID_F = "";
    String x_Naziv_F = "";

    // Load Key for record
    String key = "";
    if(rs.getString("ID_F") != null){
        key = rs.getString("ID_F");
    }

    // ID_F
    if (rs.getString("ID_F") != null){
        x_ID_F = rs.getString("ID_F");
    }else{
        x_ID_F = "";
    }

    // Naziv_F
    if (rs.getString("Naziv_F") != null){
        x_Naziv_F = rs.getString("Naziv_F");
    }else{
        x_Naziv_F = "";
    }
%>
    <tr bgcolor="<%= bgcolor %>">
        <td><span class="jspmaker"><% out.print(x_ID_F); %></span>&nbsp;</td>
        <td><span class="jspmaker"><% out.print(x_Naziv_F); %></span>&nbsp;</td>
<td><span class="jspmaker"><a href="<% key =  rs.getString("ID_F"); 
if (key != null && key.length() > 0) { 
    out.print("Formatview.jsp?key=" + java.net.URLEncoder.encode(key,"UTF-8"));
}else{
    out.print("javascript:alert('Invalid Record! Key is null');");
} %>">View</a></span></td>
<td><span class="jspmaker"><a href="<% key =  rs.getString("ID_F"); 
if (key != null && key.length() > 0) { 
    out.print("Formatedit.jsp?key=" + java.net.URLEncoder.encode(key,"UTF-8"));
}else{
    out.print("javascript:alert('Invalid Record! Key is null');");
} %>">Edit</a></span></td>
<td><span class="jspmaker"><a href="<% key =  rs.getString("ID_F"); 
if (key != null && key.length() > 0) { 
    out.print("Formatadd.jsp?key=" + java.net.URLEncoder.encode(key,"UTF-8"));
}else{
    out.print("javascript:alert('Invalid Record! Key is null');");
} %>">Copy</a></span></td>
<td><span class="jspmaker"><a href="<% key =  rs.getString("ID_F"); 
if (key != null && key.length() > 0) { 
    out.print("Formatdelete.jsp?key=" + java.net.URLEncoder.encode(key,"UTF-8"));
}else{
    out.print("javascript:alert('Invalid Record! Key is null');");
} %>">Delete</a></span></td>
    </tr>
<%

//    }
}
}
%>
</table>
</form>
<%

// Close recordset and connection
rs.close();
rs = null;
stmt.close();
stmt = null;
conn.close();
conn = null;
}catch(SQLException ex){
    out.println(ex.toString());
}
%>
<table border="0" cellspacing="0" cellpadding="10"><tr><td>
<%
boolean rsEof = false;
if (totalRecs > 0) {
    rsEof = (totalRecs < (startRec + displayRecs));
    int PrevStart = startRec - displayRecs;
    if (PrevStart < 1) { PrevStart = 1;}
    int NextStart = startRec + displayRecs;
    if (NextStart > totalRecs) { NextStart = startRec;}
    int LastStart = ((totalRecs-1)/displayRecs)*displayRecs+1;
    %>
<form>
    <table border="0" cellspacing="0" cellpadding="0"><tr><td><span class="jspmaker">Page</span>&nbsp;</td>
<!--first page button-->
    <% if (startRec==1) { %>
    <td><img src="images/firstdisab.gif" alt="First" width="20" height="15" border="0"></td>
    <% }else{ %>
    <td><a href="Formatlist.jsp?start=1"><img src="images/first.gif" alt="First" width="20" height="15" border="0"></a></td>
    <% } %>
<!--previous page button-->
    <% if (PrevStart == startRec) { %>
    <td><img src="images/prevdisab.gif" alt="Previous" width="20" height="15" border="0"></td>
    <% }else{ %>
    <td><a href="Formatlist.jsp?start=<%=PrevStart%>"><img src="images/prev.gif" alt="Previous" width="20" height="15" border="0"></a></td>
    <% } %>
<!--current page number-->
    <td><input type="text" name="pageno" value="<%=(startRec-1)/displayRecs+1%>" size="4"></td>
<!--next page button-->
    <% if (NextStart == startRec) { %>
    <td><img src="images/nextdisab.gif" alt="Next" width="20" height="15" border="0"></td>
    <% }else{ %>
    <td><a href="Formatlist.jsp?start=<%=NextStart%>"><img src="images/next.gif" alt="Next" width="20" height="15" border="0"></a></td>
    <% } %>
<!--last page button-->
    <% if (LastStart == startRec) { %>
    <td><img src="images/lastdisab.gif" alt="Last" width="20" height="15" border="0"></td>
    <% }else{ %>
    <td><a href="Formatlist.jsp?start=<%=LastStart%>"><img src="images/last.gif" alt="Last" width="20" height="15" border="0"></a></td>
    <% } %>
    <td><a href="Formatadd.jsp"><img src="images/addnew.gif" alt="Add new" width="20" height="15" border="0"></a></td>
    <td><span class="jspmaker">&nbsp;of <%=(totalRecs-1)/displayRecs+1%></span></td>
    </td></tr></table>
</form>
    <% if (startRec > totalRecs) { startRec = totalRecs;}
    stopRec = startRec + displayRecs - 1;
    recCount = totalRecs - 1;
    if (rsEof) { recCount = totalRecs;}
    if (stopRec > recCount) { stopRec = recCount;} %>
    <span class="jspmaker">Records <%= startRec %> to <%= stopRec %> of <%= totalRecs %></span>
<% }else{ %>
    <span class="jspmaker">No records found</span>
<p>
<a href="Formatadd.jsp"><img src="images/addnew.gif" alt="Add new" width="20" height="15" border="0"></a>
</p>
<% } %>
</td></tr></table>
<%@ include file="footer.jsp" %>


Konekciju sam zamislio da mi ide preko:
"db.jsp"
Code:
<%@ page import="java.sql.*"%>
<%
try{
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
}catch (Exception e){
    out.println(e.toString());
}
String xDb_Conn_Str = "jdbc:oracle:thin:@localhost:1521:xe";
Connection conn = null;
try{
    conn = DriverManager.getConnection(xDb_Conn_Str,"nikola","nick");
}catch (SQLException e){
    out.println(e.toString());
}
%>
 
Odgovor na temu

nemnesic
nemnesic
Software Developer
Vranje Florida

Moderator
Član broj: 44355
Poruke: 802
*.com
Via: [es] mailing liste



+64 Profil

icon Re: java.sql.SQLException: SQL string is not Query24.10.2007. u 18:46 - pre 200 meseci
pa sta ti log kaze kad uradis ovo: out.println(strsql);
 
Odgovor na temu

infob

Član broj: 144678
Poruke: 34
91.191.15.*



Profil

icon Re: java.sql.SQLException: SQL string is not Query24.10.2007. u 20:56 - pre 200 meseci
Da varijabla nije pronadjena ni u jednom fajlu, koji se kompajlira
 
Odgovor na temu

zigizig

Član broj: 42968
Poruke: 167
*.wifi.b92.net.



+10 Profil

icon Re: java.sql.SQLException: SQL string is not Query25.10.2007. u 08:33 - pre 199 meseci
Mala preporuka:
Kada radiš konkatenaciju string-a kao što radiš sa "strsql" nemoj da koristiš String već StringBuffer. Novi string dodaješ sa strsql.append, a na kraju uradiš strsql.toString()
 
Odgovor na temu

augustus
Novi Sad - Beograd

Član broj: 101581
Poruke: 358
*.static.sbb.co.yu.



+46 Profil

icon Re: java.sql.SQLException: SQL string is not Query25.10.2007. u 08:42 - pre 199 meseci
Zasto to preporucujes?
"Čovek je biće koje se na sve navikava, i ja mislim da je ovo njegova najbolja definicija."
Fjodor M. Dostojevski
 
Odgovor na temu

hyle
Perica Milošević
Belgrade

Član broj: 30030
Poruke: 150
77.247.200.*

Sajt: www.linkedin.com/in/peric..


+4 Profil

icon Re: java.sql.SQLException: SQL string is not Query25.10.2007. u 08:43 - pre 199 meseci
Nisi napisao u kom redu je došlo do greške, sigurno postoji neki stackTrace na osnovu koga bi bilo lakše da se pronađe greška

Probaj da umesto
Code:
stmt.executeQuery("ALTER SESSION SET CURRENT_SCHEMA = NIKOLA");

napišeš:
Code:
stmt.executeUpdate("ALTER SESSION SET CURRENT_SCHEMA = NIKOLA");

 
Odgovor na temu

hyle
Perica Milošević
Belgrade

Član broj: 30030
Poruke: 150
77.247.200.*

Sajt: www.linkedin.com/in/peric..


+4 Profil

icon Re: java.sql.SQLException: SQL string is not Query25.10.2007. u 08:55 - pre 199 meseci
Citat:
augustus: Zasto to preporucujes?

Evo, izvrši ovaj programčić i sve će ti se samo kasti ;)
Code:

public class TestStringBuffer {

   public static void main(String[] args) {

      // pravljenje stringa: 1, 2, 3, 4, 5...
      final int totalNumbers = 20000;

      long startTime = System.currentTimeMillis();
      String resultString1 = "";
      for (int i = 0; i < totalNumbers; i++)
         resultString1 = resultString1 + i + ", ";
      System.out.println("String kreiran spajanjem za " + (System.currentTimeMillis() - startTime) + "ms.");

      startTime = System.currentTimeMillis();
      StringBuffer resultBuffer =  new StringBuffer();
      for (int i = 0; i < totalNumbers; i++)
         resultBuffer.append(i).append(", ");
      resultBuffer.toString();
      System.out.println("String kreiran koriscenjem StringBuffera za " + (System.currentTimeMillis() - startTime) + "ms.");

   }

}
 
Odgovor na temu

augustus
Novi Sad - Beograd

Član broj: 101581
Poruke: 358
*.static.sbb.co.yu.



+46 Profil

icon Re: java.sql.SQLException: SQL string is not Query25.10.2007. u 09:15 - pre 199 meseci
Preporuka stoji pod uslovom da spajas ogroman broj stringova.
Ako spajas stringove za sql upit ili nesto slicno neces dobiti na brzini. Vreme izvrsavanja je isto.

"Čovek je biće koje se na sve navikava, i ja mislim da je ovo njegova najbolja definicija."
Fjodor M. Dostojevski
 
Odgovor na temu

hyle
Perica Milošević
Belgrade

Član broj: 30030
Poruke: 150
77.247.200.*

Sajt: www.linkedin.com/in/peric..


+4 Profil

icon Re: java.sql.SQLException: SQL string is not Query25.10.2007. u 09:52 - pre 199 meseci
Vreme će biti isto ako u jednoj liniji uradiš spajanje:
Code:

String tmp = "asd" + "jkl" + "qwer";


Ako ovo spajanje uradiš kao:
Code:

String tmp = "asd";
tmp += "jkl";
tmp += "qwer";

U tom slučaju vreme neće biti isto.

Fora kod prvog spajanja je što kompajler radi optimizaciju i prevede tu liniju i isti kod koji bi dobio da si koristio StringBuffer i tada sasvim ok spajati Stringove na taj način jer je čitljivije.
Ako imaš neko spajanje u više redova preporučljivo je da koristiš StringBuffer.


Možda je kompajler u Javi 6 pametan, pa znao i ovo drugo da optimizuje, ranije nije znao
 
Odgovor na temu

augustus
Novi Sad - Beograd

Član broj: 101581
Poruke: 358
*.static.sbb.co.yu.



+46 Profil

icon Re: java.sql.SQLException: SQL string is not Query25.10.2007. u 10:18 - pre 199 meseci
E ovo je vec lepo saznanje.

Thanks
"Čovek je biće koje se na sve navikava, i ja mislim da je ovo njegova najbolja definicija."
Fjodor M. Dostojevski
 
Odgovor na temu

infob

Član broj: 144678
Poruke: 34
91.191.15.*



Profil

icon Re: java.sql.SQLException: SQL string is not Query25.10.2007. u 17:55 - pre 199 meseci
Momci, hvala svima! Rijesio sam problem. Svaki odgovor je pomogao, naravno, ali radi svih, koji citaju ovo, hocu da napomenem da je kljucno rjesenje bilo da se, kao sto je hyle rekao, zamijeni dio koda:
Code:
stmt.executeQuery("ALTER SESSION SET CURRENT_SCHEMA = NIKOLA");

, a trebalo je:

Code:
stmt.executeUpdate("ALTER SESSION SET CURRENT_SCHEMA = NIKOLA");


Nadam se da vise necu imati problema sa izradom aplikacije ali i ako ih bude, sad vidim gdje i kome treba da se obratim.
Pozdrav!
 
Odgovor na temu

[es] :: Java :: java.sql.SQLException: SQL string is not Query

[ Pregleda: 2766 | Odgovora: 10 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.