Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 error in create table n have phone in '###-###-###

Author  Topic 

eskimo
Starting Member

1 Post

Posted - 2008-03-26 : 10:33:33

C:\z\project>javac CraySystems.java

C:\z\project>java CraySystems
Error occured
Error :java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Timeout expired

Error occured
Error :java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Inc
orrect syntax near 'state'.
Error occured
Error :java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]The
re is already an object named 'Executive' in the database.
Error occured
Error :java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Inc
orrect syntax near the keyword 'desc'.
Error occured
Error :java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]The
re is already an object named 'Branch' in the database.

C:\z\project>
here is the code,
import java.sql.*;
public class CraySystems
{
public static void main(String args[])
{
try
{
String str="CREATE TABLE shipping"
+"(b_code INT NOT NULL DEFAULT 1,"
+"p_name VARCHAR(30),"
+"pay_m VARCHAR(20),"
+"sex VARCHAR(20),"
+"f_name VARCHAR(30),"
+"phone VARCHAR(15)not null,check (phone like'[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9]'),"
+"address VARCHAR(30),"
+"city VARCHAR(20),"
+"state VARCHAR(30),"
+"zip VARCHAR(15),"
+"country VARCHAR(20)"
+"PRIMARY KEY(b_code))";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:fatjoy","sa","");
Statement stmt=con.createStatement();
stmt.execute(str);
System.out.println("Shipping Table Created!!!");
}
catch(Exception ex)
{
System.out.println("Error occured");
System.out.println("Error :"+ex);
}
try
{
String str="CREATE TABLE Employee"
+"(emp_id INT NOT NULL DEFAULT 1,"
+"fname VARCHAR(30),"
+"lname VARCHAR(30),"
+"address VARCHAR(50),"
+"city VARCHAR(15,"
+"state VARCHAR(20),"
+"zip VARCHAR(10) ,"
+"phone VARCHAR(15)not null,check (phone like'[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9]'),"
+"design VARCHAR(30),"
+"doj DATETIME NOT NULL DEFAULT GetDate(),"
+"dob DATETIME NOT NULL DEFAULT GetDate(),"
+"email VARCHAR(15),"
+"b_code INT NOT NULL DEFAULT 1,"
+"pwd VARCHAR(20)"
+"PRIMARY KEY(emp_id))";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:fatjoy","sa","");
Statement stmt=con.createStatement();
stmt.execute(str);
System.out.println("Employee Table Created!!!");
}
catch(Exception ex)
{
System.out.println("Error occured");
System.out.println("Error :"+ex);
}
try
{
String str="CREATE TABLE Executive"
+"(Ex_id INT NOT NULL DEFAULT 1,"
+"Ex_fname VARCHAR(30),"
+"Ex_lname VARCHAR(30),"
+"sex VARCHAR(20),"
+"b_code INT NOT NULL DEFAULT 1"
+"PRIMARY KEY(Ex_Id ,b_code))";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:fatjoy","sa","");
Statement stmt=con.createStatement();
stmt.execute(str);
System.out.println("Executive Table Created!!!");
}
catch(Exception ex)
{
System.out.println("Error occured");
System.out.println("Error :"+ex);
}
try
{
String str="CREATE TABLE Product"
+"(p_name VARCHAR(30),"
+"p_code INT NOT NULL DEFAULT 1,"
+"desc VARCHAR(60)not null,"
+"emp_id INT NOT NULL DEFAULT 1,"
+"price DECIMAL(10,2)NOT NULL,"
+"DatePosted DATETIME NOT NULL DEFAULT GetDate()"
+"PRIMARY KEY(p_code ,emp_id))";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:fatjoy","sa","");
Statement stmt=con.createStatement();
stmt.execute(str);
System.out.println("Product Table Created!!!");
}
catch(Exception ex)
{
System.out.println("Error occured");
System.out.println("Error :"+ex);
}
try
{
String str="CREATE TABLE Branch"
+"(b_code INT NOT NULL DEFAULT 1,"
+"office_add VARCHAR(50),"
+"city VARCHAR(20),"
+"state VARCHAR(20),"
+"zip VARCHAR(10),"
+"fname VARCHAR(20)"
+"PRIMARY KEY(b_code))";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:fatjoy","sa","");
Statement stmt=con.createStatement();
stmt.execute(str);
System.out.println("Branch Table Created!!!");
}
catch(Exception ex)
{
System.out.println("Error occured");
System.out.println("Error :"+ex);
}
}
}
pls,kindly assists me on this.

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2008-03-26 : 10:35:23
Don't execute SQL strings at clients. Use stored procedures.

And, most important of all: don't just cut and paste code that is not working without making any effort to explain it, and expect people to help you.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -