Results 1 to 2 of 2
- 03-26-2008, 12:01 PM #1
Member
- Join Date
- Mar 2008
- Posts
- 13
- Rep Power
- 0
unable to exceute stored procedures
import java.sql.*;
public class CrTable
{
//Add an employee to the database.
public static void addEmp(int emp_id, String emp_f_name,
String emp_l_name,float emp_salary) {
System.out.println("Creating new employee...");
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
Connection con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=master;user=sa;passwor d=remora");
System.out.println("connceted----->"+con.getClass());
String sql =
"INSERT INTO emp " +
"(emp_id,emp_f_name,emp_l_name,emp_salary)" +
"VALUES(?,?,?,?)";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setInt(1,emp_id);
pstmt.setString(2,emp_f_name);
pstmt.setString(3,emp_l_name);
pstmt.setFloat(4,emp_salary);
pstmt.executeUpdate();
pstmt.close();
}
catch(Exception e)
{
System.err.println("ERROR! Adding Employee: "
+ e.getMessage());
}
}
}
When i am running the above program I am getting the out put like this
The Selection Doesnot support Runmode
what is the meaning of that error
how can i resolve this problem
any one can help solving this problem
Geeta
- 04-22-2008, 02:39 AM #2
Member
- Join Date
- Apr 2008
- Posts
- 28
- Rep Power
- 0
first of all: JDBC is recommending that the DataSource interface should be used to create database connection objects instead of using the DriverManager class.
check here: Implementations of the DataSource Interface
Second put your code in code blocks, its too hard to read.
Third pstmt.setInt(1,emp_id); You seem to be telling it what column to insert to twice. 1 is the order, emp_id is the column name. Change that column name to what you actually want to enter into that field.
Similar Threads
-
Executing stored procedures
By mew in forum JDBCReplies: 3Last Post: 08-20-2008, 05:47 PM -
Stored Procedures
By geeta_ravikanti in forum JDBCReplies: 1Last Post: 04-22-2008, 02:34 AM -
Stored Procedures with java
By Albert in forum JDBCReplies: 4Last Post: 06-08-2007, 05:59 AM -
stored procedures in Hibernate
By Alan in forum JDBCReplies: 2Last Post: 05-31-2007, 04:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks