
CREATE TABLE mohan2 (
sno bigint(20) NOT NULL AUTO_INCREMENT,
name varchar(30) NOT NULL,
sal int(30) NOT NULL,
eid varchar(30) NOT NULL,
PRIMARY KEY (sno,eid)
)
import java.sql.*;
import java.util.*;
public class sample3
{
static int Generate(String name1,int t)
{
int len=5;
int x=0;
Connection conn = null;
Statement st=null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "test";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "password";
String eid="";
try
{
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
st=conn.createStatement();
ResultSet rs=st.executeQuery("select max(sno) from mohan2");
rs.next();
int s=rs.getInt(1);
System.out.println(s);
s=s+1;
StringBuffer sb = new StringBuffer(len);
sb.append("P");
len=len-1;
String v=String.valueOf(s);
int p=v.length();
len=len-p;
while(len--!=0)
sb.append("0");
sb.append(v);
eid=sb.toString();
rs.close();
st.close();
st=conn.createStatement();
x=st.executeUpdate("insert into mohan2(eid,name,sal) values('"+eid+"','"+name1+"',"+t+")"); <br />
st.close();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return x;
}
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter emp name:");
String str=s.next();
System.out.println("Enter emp sal:");
int sal=s.nextInt();
//sample3 s1=new sample3();
int x=Generate(str,sal);
if(x==1)
System.out.println("Data is inserted");
else
System.out.println("data is not inserted");
}
}
how can write this program in jsp its working on console but in jsp it shown internal error? how to write above code in jsp please help me i will sumbit the project in two days please sir
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.