Home arrow static arrow Java Programming [Archive] - java and sql
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - java and sql
This topic has 2 replies on 1 page.

Posts:2
Registered: 7/26/04
java and sql  
Aug 2, 2004 7:45 AM



 
Hi there
I have the following code and it seems that the sql query isn't correct. when i try to display the data from the resultset it gives an invalid cursor state. i have checked the query by trying it in the access databse and it works fine. Can you please telle me where's the prob thanks
here is my code


import java.sql.*;

public class first_data {
public static void main(String args[]) throws SQLException, ClassNotFoundException{
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException cls){
cls.printStackTrace();
}

try{

Connection conn = DriverManager.getConnection("jdbc:odbc:mb1");

Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
String query = "SELECT Name, Surname FROM Table1 WHERE Surname LIKE '*' & 'denisl' & '*'";

System.out.println(query);
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String s = rs.getString("Name");
System.out.println(rs.getRow());
String n = rs.getString("Surname");
System.out.println(s + " " + n);

}
rs.close();
stmt.close();
conn.close();
}
catch(SQLException sql){
sql.printStackTrace();
}

}

}

 

Posts:87
Registered: 00-05-05
Re: java and sql  
Aug 2, 2004 7:53 AM (reply 1 of 2)



 
WHERE Surname LIKE '%denisl%'
 

Posts:24,517
Registered: 98-02-27
Re: java and sql  
Aug 2, 2004 12:44 PM (reply 2 of 2)



 
You should use a PreparedStatement so you don't need to worry about the correct punctuation of your data.
 
This topic has 2 replies on 1 page.